The problem is fixed by specifying your regex using m{} instead of ??.
#!/usr/bin/perl use strict ; ######################################################## ######## START MAIN #################### my @STAGE=( '/stage/core/HPUX/PA-RISC-64/64bit/rdbms/10.2.0.1.0/dvd2/clusterwa +re', '/stage/core/HPUX/PA-RISC-64/64bit/rdbms/patches/10.2.0.4.0/Disk1' ); for my $i (0..5){ my $o_vers ; my $j = $i & 1; $o_vers = $1 if $STAGE[$j] =~ m{/rdbms/([\d.]+)/}; $o_vers = $1 if $STAGE[$j] =~ m{/rdbms/patches/([\d.]+)/}; print "Iteration# $i: Version is: $o_vers\n" ; }
Also note, you could combine your two regex's like so:
for my $i (0..5){ my $j = $i & 1; my $o_vers = $STAGE[$j] =~ m{/rdbms/(?:patches/)?([\d.]+)/} ? $1 : +''; print "Iteration# $i: Version is: $o_vers\n" ; }
- Miller
In reply to Re: Pattern matching & capturing strange behaviour.
by wind
in thread Pattern matching & capturing strange behaviour.
by NevilleG
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |