Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Modifying a reference to a literal string

by hdp (Beadle)
on May 02, 2001 at 19:53 UTC ( [id://77375] : note . print w/replies, xml ) Need Help??


in reply to Modifying a reference to a literal string

I'm not sure why there's a difference -- I don't have a windows machine to test it on, but I would have expected the "attempt to modify readonly value" error everywhere.

Keep in mind that you can directly modify the parameters passed to a function by messing with @_. You don't need to use \shift; I suggest rewriting modify_string as:

sub modify_string { $_[0] =~ s/u/i/; return $_[0]; }
Your way isn't "wrong", but (relatively) it does a lot of extra work.

hdp.