
daltonmv
New User
Nov 13, 2009, 9:04 AM
Post #1 of 4
(1971 views)
|
|
Unexpected results from assignment with regex match
|
Can't Post
|
|
This one doesn't make sense at all. I'm trying to grab the primary or main version number from a string kept in a file that is maintained by product patches. Here is a snippet of Perl code that reads the single line from that file and attempts to isolate that primary version number. 30 printf "We\'re running Perl %vd.\n", $^V; 31 32 $SID="%W%"; 33 $RELEASE="%I%"; 34 35 use Getopt::Std; 36 use Sys::Hostname; 37 use Date::Format; 38 39 #raw_NBU_version=$(</usr/openv/netbackup/bin/version) 40 #full_NBU_version=${raw_NBU_version##NetBackup-Solaris} 41 #whittled_NBU_version=${full_NBU_version##* } 42 #main_NBU_version=${whittled_NBU_version%%.*} 43 #if (( main_NBU_version < 6 )) 44 #then 45 # echo "NBU Version must be 6 or greater!" 46 # exit 99 47 #fi 48 $NBU_version_file = "/usr/openv/netbackup/bin/version"; 49 open(my $NBU_VERSION, "<", $NBU_version_file) or die "Can't open NBU version file: $! $?\n"; 50 if ( defined(my $NBU_version = <$NBU_VERSION>) ) { 51 chomp($NBU_version); 52 print "$NBU_version\n"; 53 my $main_NBU_version = ($NBU_version =~ s/^NetBackup-Solaris10\s+(\d+)\.\d+\.\d+.*/$1/); 54 print "The main NBU version is \"$main_NBU_version\"\n"; 55 # if (my $main_NBU_version = ($raw_NBU_version =~ /^NetBackup-Solaris10\s+(\d+)\..*/)) { 56 # print "$main_NBU_version\n"; 57 # } 58 } 59 close($NBU_VERSION); 60 When I run it, I get this: We're running Perl 5.8.4. NetBackup-Solaris10 6.5.4 The main NBU version is "1" I can't for the life of me figure out where the digit "1" comes from. If I run a "sed" script using essentially the same regex against the same input file, I get what I expected to get: sed -e 's/^NetBackup\-Solaris10 \([0-9]\{1,\}\)\.[0-9]\{1,\}\.[0-9]\{1,\}/\1/' /usr/openv/netbackup/bin/version 6 What do I not understand about the Perl implementation of regex processing? Thanks for any help offered.
|