in reply to Bug with substring return value?
in Perl in a Nutshell it states... "You can also specify a replacement string in the fourth parameter to replace the substring. The original extracted substring is still returned."
The Nutshell book is right, but you don't use the fourth parameter. You use three parameters, and use substr as an lvalue that can be assigned to.
What you want is:# Begin of assignment substr( # Start of substr call, using substr as lvalue $string, # First argument 2, # Second argument 6 # Third argument ) # Anything after this is not part of the substr call = # Assignment operator ''; # Righthand operand of the assignment operator # End of assignment. An assignment returns the assigned value, # '' in this case.
You could have found out by reading substr's entry in perlfunc, which begins with all ways of calling it:substr( # Start of substr call, returning the old stuff $string, # First argument 2, # Second argument 6, # Third argument '' # Fourth argument: replacement text );
substr EXPR,OFFSET,LENGTH,REPLACEMENT
substr EXPR,OFFSET,LENGTH
substr EXPR,OFFSET
- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Bug with substring return value?
by shotgunefx (Parson) on Apr 14, 2002 at 00:08 UTC |