SPUG: idioms of late

Ronald J Kimball rjk-spug at tamias.net
Tue Jan 19 09:18:39 PST 2010


On Mon, Jan 18, 2010 at 11:59:10PM -0800, Michael R. Wolf wrote:
> 
> On Jan 18, 2010, at 3:39 PM, Joshua Juran wrote:
> 
> >You have to use a copy of $_ because $_ is read-only in map.
> 
> Thanks for the reminder.  I, too, have started using a bit more  
> functional-style Perl of late.  It's good to be reminded of the  
> limitations.

*rolls eyes*

Again, $_ is not read-only in map.  It is aliased to the original value.
Changes made to $_ will affect the original value.  The original code could
have been written as:

map { s/\.$// } @{$foo->{names}};


(If the original value is read-only, then $_ will be read-only, but that's
true for any approach that involves aliasing, not just map.)

Ronald


More information about the spug-list mailing list