logo       

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

perl-beginners

Subject: Re: On using $_ in subroutines

On Mon, Jul 27, 2009 at 09:49, Bryan Harris<bryanslists@xxxxxxxxx> wrote:
snip
>> 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?
snip

Take a look at [Perl Best Practices][1] by Damian Conway (chapter 5
covers variable use), but be warned, not all of the advice in PBP is
still considered correct. Another good resource is [Perl::Critic][2],
but, again, you do not have to follow everything it tells you. You
will also want to read about the [my][3], [our][4], and [local][5]
functions and anywhere in the docs where the talk about lexical (my)
or dynamic (our & local) scope, including, but not limited to the
[Private Variables via my()][6] and [Temporary Values via local()][7]
sections of perlsub.

snip
> 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.)
snip

Because Apple is being conservative (and rightly so, 5.10.0 has a lot
of bugs). The next release (Snow Leopard) will have 5.10, and you can
always compile it yourself or use [ActiveState's version][8]. In
fact, there are those in the community who claim you should never
trust a vendor supplied version of Perl and should always compile your
own copy.

[1] : http://oreilly.com/catalog/9780596001735/
[2] : http://search.cpan.org/dist/Perl-Critic/lib/Perl/Critic.pm
[3] : http://perldoc.perl.org/functions/my.html
[4] : http://perldoc.perl.org/functions/our.html
[5] : http://perldoc.perl.org/functions/local.html
[6] : http://perldoc.perl.org/perlsub.html#Private-Variables-via-my%28%29
[7] : http://perldoc.perl.org/perlsub.html#Temporary-Values-via-local()
[8] : http://www.activestate.com/activeperl/

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
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