in reply to Re^2: Regex question
in thread Regex question
This will never match and is completly wrong as you mixed up $var1 and $var2.
Um, no.
C:\parrot>p1 [0] Perl> $var1 = '1.1.2'; $var2 = '1.1'; if( index( $var1, $var2 ) == 0 ) { print "matches" } else { print "Doesn't match" };; matches [0] Perl> $var1 = '1.1.2'; $var2 = '1.1'; if( index( $var2, $var1 ) == 0 ) { print "matches" } else { print "Doesn't match" };; Doesn't match
but this will still be wrong because
$var2='1.11.2'; $var1='1.1';would give you a false match
That's a good catch though. It's also easily fixed:
[0] Perl> $var1 = '1.11.2'; $var2 = '1.1'; if( index( $var1, "$var2." ) == 0 ) { print "matches" } else { print "Doesn't match" };; Doesn't match
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Regex question
by Skeeve (Parson) on May 22, 2007 at 22:47 UTC |