in reply to Pattern matching & capturing strange behaviour.

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

Replies are listed 'Best First'.
Re^2: Pattern matching & capturing strange behaviour.
by NevilleG (Initiate) on Mar 22, 2011 at 01:40 UTC
    Thanks a ton. That did the trick. I was only using '?' as a different delimiter to '/'. Didn't realise the full implication.