in reply to Finding location
Just note that the strings '12*' and '123' will both yield 3 ...my $loc = (index($s, '*')+1) || length($s);
Or, w/zero-base (so '12*'=>2 and '123'=>3), can do:my $loc = (index($s, '*')+1) || (length($s)+1);
maybe not the clearest--but one-line, if that's your definition of "elegant" :)my $loc = ( (index($s, '*')+1) || (length($s)+1) ) - 1;
my $loc = do { my $i = index $s, '*'; $i < 0 ? length($s) : $i };
|
|---|