Hello Harry, On Fri, 30 Dec 2011 10:03:30 -0800 (PST) Harry <kaichow...@gmail.com> wrote:
> I am confused what this variable does: $_ > > If someone could give an example or explanation of what this variable $_ does > in perl, that would be great! $_ is the default variable, which gets assigned to and used in various contexts. You can think of it as the pronoun "it" in English. Personally, I feel that overusing $_ is not recommended in most serious programs, because it is easily devastated, but: 1. You sometimes need to use it, like in http://perldoc.perl.org/functions/map.html , http://perldoc.perl.org/functions/grep.html , as well as some other functions from List::Util , List::MoreUtils , List::UtilsBy and similar modules (and even then, it is sometimes useful to assign it to a lexical "my" variable.). 2. It is sometimes useful in one-off programs and scripts, especially perl -pe/perl -ne/perl -pale/perl -lane/etc. scripts (where people also allow for omitting "use strict;" and "use warnings;". Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Public Domain Photos - http://www.flickr.com/photos/shlomif/ Larry Wall gets the colon. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/