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

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread

Thanks..
NaradiDear experts,
I am a newbie in windows batch scripting and to this forum. If this is not a right forum for this post, please let me know. I apologize for the post in WRONG forum.

To clarify earlier request further..

I would like to extract the version number of perl installed in different folders.

examples of relevant texts of "perl -v" are given in my previous post...

Thanks again...

-------------
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

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread

Thanks..
Naradi Quote from: naradi on July 14, 2010, 05:58:26 PM

based on different versions of Perl, how do I extract the version number (e.g. 5.10 or 5.12) in the examples below

This is perl, v5.10.0 built for MSWin32-x86-multi-thread
This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread

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



Discussion

No Comment Found