in reply to out of two strings which occurs first in a text
my $posa = index($str, $stra); my $posb = index($str, $strb); if ($posa < 0 || $posb < 0) { print("$stra doesn't occur\n") if $posa < 0; print("$strb doesn't occur\n") if $posb < 0; } elsif ($posa < $posb) { print("$stra first occurs before $strb\n"); } elsif ($posa > $posb) { print("$strb first occurs before $stra\n"); } else { print("$stra and $strb first occur at the same location\n"); }
Update: Added missing braces.
|
|---|