JediWizard has asked for the wisdom of the Perl Monks concerning the following question:
I was about to comment (sarcastically) on Removing underscores. when I got confused by somehting, so I am here seeking knowledge from a monk wiser than I. I tried this:
perl -e 'my $str = "This_is_a_song_.mp3"; substr($str, 14, 1, ''); pri +nt $str."\n";'
and got:
This_is_a_song_.mp3
I would have expected substr to remove the last underscore (the character at offset 14). However it appears that because my replacement had a length of zero, perl acted as though I hadn't given it a replacement. Does the "REPLACEMENT" argument to substr need to have length in order to be considered valid?
Update: My ignorance has been discovered. Thank you all for sharing your knowledge
They say that time changes things, but you actually have to change them yourself.
Andy Warhol
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using substr to remove characters
by Zaxo (Archbishop) on May 06, 2005 at 18:34 UTC | |
|
Re: Using substr to remove characters
by bmann (Priest) on May 06, 2005 at 18:33 UTC | |
|
Re: Using substr to remove characters
by Transient (Hermit) on May 06, 2005 at 18:32 UTC | |
|
Re: Using substr to remove characters
by thcsoft (Monk) on May 07, 2005 at 09:26 UTC | |
by JediWizard (Deacon) on May 09, 2005 at 13:34 UTC |