in reply to Problem with substr
"e.coli.replaced becomes e.coli (which is fine)
It doesn't. With your code it becomes "e.coli.".
"but z.mays becomes z.may (which isn't)."
Don't assume what rindex returns, try this for your test case:
print rindex( $name, q{replaced} );
A simpler way of doing this would be:
my $name = "e.coli.replaced"; $name =~ s/.replaced//;
Should you actually wish the outcome to be as you specified and not what your code actually does.
Update: Fixed typo
Update 2: Dang, this is a must read, catches my mistake.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Problem with substr
by AnomalousMonk (Archbishop) on May 14, 2013 at 19:34 UTC | |
Re^2: Problem with substr
by newbie1991 (Acolyte) on May 14, 2013 at 16:19 UTC |
In Section
Seekers of Perl Wisdom