1.

Solve : how to extract version of perl while using batch file?

Answer» <html><body><p>Dear experts..<br/>based on different versions of Perl, how do I extract the version number (e.g. 5.10 or 5.12) in the examples below<br/><br/>This is perl, v5.10.0 built for MSWin32-x86-multi-thread<br/>This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread<br/><br/>Thanks..<br/>NaradiDear experts, <br/>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 <a href="https://interviewquestions.tuteehub.com/tag/wrong-1462035" style="font-weight:bold;" target="_blank" title="Click to know more about WRONG">WRONG</a> forum. <br/><br/>To clarify earlier request further..<br/><br/>I would like to extract the version number of perl installed in different folders.<br/><br/>examples of relevant texts of "perl -v" are given in my previous post...<br/><br/>Thanks again...<br/><br/>-------------<br/>Dear experts..<br/>based on different versions of Perl, how do I extract the version number (e.g. 5.10 or 5.12) in the examples below<br/><br/>This is perl, v5.10.0 built for MSWin32-x86-multi-thread<br/>This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread<br/><br/>Thanks..<br/>Naradi Quote from: naradi on July 14, 2010, 05:58:26 PM</p><blockquote>based on different versions of Perl, how do I extract the version number (e.g. 5.10 or 5.12) in the examples below<br/><br/>This is perl, v5.10.0 built for MSWin32-x86-multi-thread<br/>This is perl 5, version 12, subversion 1 (v5.12.1) built for MSWin32-x86-multi-thread<br/></blockquote> <br/>The following snippet should help you out. I'm a bit confused. Do you have two versions of Perl installed or do you just <a href="https://interviewquestions.tuteehub.com/tag/want-1448756" style="font-weight:bold;" target="_blank" title="Click to know more about WANT">WANT</a> the version of Perl that is installed?<br/><br/> Code: <a>[Select]</a>echo off<br/>setlocal<br/><br/>for /f "tokens=4" %%i in ('perl -v ^| find /i "This is perl, "') do (<br/>  if not errorlevel 1 echo %%i<br/>)<br/><br/>for /f "tokens=9 delims=()" %%i in ('perl -v ^| find /i "This is perl 5, "') do (<br/>  if not errorlevel 1 echo %%i<br/>)<br/><br/>Good luck and welcome to the forum Thanks so much for your response.. <br/><br/>Different machines have different versions of perl installed and I want to extract the version # using a <a href="https://interviewquestions.tuteehub.com/tag/msdos-549596" style="font-weight:bold;" target="_blank" title="Click to know more about MSDOS">MSDOS</a> batch script. The <a href="https://interviewquestions.tuteehub.com/tag/position-246411" style="font-weight:bold;" target="_blank" title="Click to know more about POSITION">POSITION</a> 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"?<br/><br/>Thanks again,<br/>Naradi<br/><br/> Quote from: naradi on July 15, 2010, 12:38:54 PM<blockquote>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"?<br/></blockquote> <br/>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.<br/><br/>I made one <a href="https://interviewquestions.tuteehub.com/tag/small-1212368" style="font-weight:bold;" target="_blank" title="Click to know more about SMALL">SMALL</a> change to display the "v" with the 5.12.1 version.<br/><br/> Code: <a>[Select]</a>echo off<br/>setlocal<br/><br/>for /f "tokens=4" %%i in ('perl -v ^| find /i "This is perl, "') do (<br/>  if not errorlevel 1 echo %%i<br/>)<br/><br/>for /f "tokens=9 delims=()" %%i in ('perl -v ^| find /i "This is perl 5, "') do (<br/>  if not errorlevel 1 echo v%%i<br/>)<br/><br/> OP, since you are using Perl, then use Perl. It has more powerful text processing capabilities than batch<br/><br/> Code: <a>[Select]</a>C:\test&gt;perl -version | perl -ne "print if s/(.*[(,][ \t])(v\d+\.\d+\.\d+).*/\2/"<br/>v5.10.1<br/><br/></body></html>


Discussion

No Comment Found