Sravan Sravan - 10 months ago 35
Perl Question

perl script that would just print the tomcat version

I am trying to extract just the tomcat version from the command in a perl script and ran in to issue with the regex part. Any help would be greatly appreciated. Here's my code:

$tomcat_ver=`sh /usr/local/apache-tomcat-7.0.57/bin/`;
if($tomcat_ver=~ m/Server number: (.+)[0-9]$/s)
my $tomcat_version=$1;
print "$tomcat_version\n";



This regex would also do:

m/Server number: (.+)\n/)

It will match till the new line character is encountered. And to save it assign $1(predefined variable) to a custom variable where you want to store the version info.