logo       

Re: On using $_ in subroutines: msg#00391

perl-beginners

Subject: Re: On using $_ in subroutines


> Bryan Harris wrote:
>>
>> John W. Krahn wrote:
>>>
>>> Bryan Harris wrote:
>>>>
>>>> ... but by modifying $_ I was clobbering $_ elsewhere in the larger
>>>> program!
>>> Yes because $_ is a special global variable. This effect is called
>>> "action at a distance" which is why it is better to use named lexically
>>> scoped variables instead of $_.
>>
>> I have the Perl Bookshelf on CD (and perldoc, obviously) -- where can I read
>> more about this?
>
> perldoc perlvar
>
> http://shoebox.net/articles/perl-warts.html
> http://en.wikipedia.org/wiki/Action_at_a_distance_(computer_science)

Great info, thanks.

Curiously, perlvar seems to recommend localizing $_ with "local", but I
thought I read somewhere to never use local and only use my. I still don't
understand how those two are different.



>>>> Oddly, perl won't let me do "my ($_) = shift;", so I'm stuck having to use
>>>> another variable.
>>> Perl 5.10 *will* let you do "my $_".
>>
>> Why is perl on OS X still at 5.8.8? It's free, right? why wouldn't Apple
>> include the latest one? (I know this isn't an Apple list, just wondering if
>> anyone knows.)
>
> Perl 5.10 is still at the .0 stage (5.10.0) and a lot of people like to
> wait until software has progressed past the .0 phase.

Makes sense. What happened to Perl 5.9?

- Bryan




--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/


Google Custom Search

News | Mail Home | sitemap | FAQ | advertise