| 1. |
Solve : how to extract version of perl while using batch file? |
|
Answer» Dear experts.. based on different versions of Perl, how do I extract the version number (e.g. 5.10 or 5.12) in the examples below The following snippet should help you out. I'm a bit confused. Do you have two versions of Perl installed or do you just WANT the version of Perl that is installed? Code: [Select]echo off setlocal for /f "tokens=4" %%i in ('perl -v ^| find /i "This is perl, "') do ( if not errorlevel 1 echo %%i ) for /f "tokens=9 delims=()" %%i in ('perl -v ^| find /i "This is perl 5, "') do ( if not errorlevel 1 echo %%i ) Good luck and welcome to the forum Thanks so much for your response.. Different machines have different versions of perl installed and I want to extract the version # using a MSDOS batch script. The POSITION of version number seems to change with the text as seen from the provided examples. However, v5.XX.XX seems to be the only relevant string of characters that have, so far, remained consistent across versions. So, is there a way to extract "vX.XX.XX"? Thanks again, Naradi Quote from: naradi on July 15, 2010, 12:38:54 PM However, v5.XX.XX seems to be the only relevant string of characters that have, so far, remained consistent across versions. So, is there a way to extract "vX.XX.XX"? Did the code not work properly? I only have Perl 5.10.0 installed on my machine so I could not test version 5.12.1. If there is an error with the script please post your output. I may have miscounted the tokens. I made one SMALL change to display the "v" with the 5.12.1 version. Code: [Select]echo off setlocal for /f "tokens=4" %%i in ('perl -v ^| find /i "This is perl, "') do ( if not errorlevel 1 echo %%i ) for /f "tokens=9 delims=()" %%i in ('perl -v ^| find /i "This is perl 5, "') do ( if not errorlevel 1 echo v%%i ) OP, since you are using Perl, then use Perl. It has more powerful text processing capabilities than batch Code: [Select]C:\test>perl -version | perl -ne "print if s/(.*[(,][ \t])(v\d+\.\d+\.\d+).*/\2/" v5.10.1 |
|