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
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
|