Re: What is $_
by Pardus (Pilgrim) on Jan 20, 2003 at 12:47 UTC
|
I heard the words "topic" for $_ and "topicalizer" for any function setting $_ go around, since in linguistic sense $_ is the topic of your conversation with the parser.
In perl6 this concept will be more elaborate.
#<perl6>
my $str = "some string\n";
given $str {
chomp;
print $_." is now our topic\n";
}
#</perl6>
--
Jaap Karssenberg || Pardus (Larus)? <pardus@cpan.org>
>>>> Zoidberg: So many memories, so many strange fluids gushing out of patients' bodies.... <<<<
| [reply] [d/l] |
•Re: What is $_
by merlyn (Sage) on Jan 20, 2003 at 12:38 UTC
|
$_ The default input and pattern-searching space. The followi
+ng
pairs are equivalent:
while (<>) {...} # equivalent only in while!
while (defined($_ = <>)) {...}
/^Subject:/
$_ =~ /^Subject:/
tr/a-z/A-Z/
$_ =~ tr/a-z/A-Z/
chomp
chomp($_)
Here are the places where Perl will assume $_ even if you
+don't
use it:
* Various unary functions, including functions like ord()
+ and
int(), as well as the all file tests ("-f", "-d") excep
+t for
"-t", which defaults to STDIN.
* Various list functions like print() and unlink().
* The pattern matching operations "m//", "s///", and "tr/
+//"
when used without an "=~" operator.
* The default iterator variable in a "foreach" loop if no
+ other
variable is supplied.
* The implicit iterator variable in the grep() and map()
functions.
* The default place to put an input record when a "<FH>"
operation's result is tested by itself as the sole crit
+erion
of a "while" test. Outside a "while" test, this will no
+t
happen.
(Mnemonic: underline is understood in certain operations.)
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply. | [reply] [d/l] |
Re: What is $_
by BrowserUk (Patriarch) on Jan 20, 2003 at 13:18 UTC
|
That's a little like asking what is "The Moon" :^). Alternatively, like trying to discern a name for that squiggle that TAFKAP now (once?) use(s|d?).
Personally I've always referred to it verbally as "dollar-underscore".
Though, is the same way as the Moon can be referred to using several synonyms--Luna, the Earth's (only?) natural satellite, "heartless orb that rules night and steals the colors from our sight"--so I similarly think of it in different terms depending upon the context.
E.g. default value, default iterator, default argument etc.
Or simply "The default", though that only makes any sense with more context.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
| [reply] |
|
|
| [reply] |
|
|
++ for the Moody Blues quote
| [reply] |
Re: What is $_
by Mr. Muskrat (Canon) on Jan 20, 2003 at 15:44 UTC
|
I have always called $_, "it". However, if you use English;, it is $ARG. | [reply] [d/l] |
Re: What is $_
by OM_Zen (Scribe) on Jan 20, 2003 at 15:44 UTC
|
Hi,
The $_, I call it rummy joker(like a wildcard),the usage is bit constrained in terms of scope than the name I call.It could be called by anyname that relates to placeholder or something | [reply] |
Re: What is $_
by John M. Dlugosz (Monsignor) on Jan 21, 2003 at 00:16 UTC
|
Sometime's I've thought of it as "the accumulator". | [reply] |
Re: What is $_
by bart (Canon) on Jan 21, 2003 at 11:05 UTC
|
"It".One could call it "the anonymous variable", "the variable with no name", or "the scratch variable".
| [reply] |
Re: What is $_
by Cody Pendant (Prior) on Jan 21, 2003 at 06:15 UTC
|
According to perlvar, its longer name is "$ARG".
All of these vars we have short names for have at least one other name if you "use English;"
Some even have three, like "$." does.
--
Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer. M-J D | [reply] |
Re: What is $_
by Aristotle (Chancellor) on Jan 22, 2003 at 13:54 UTC
|
<AOL>Me too</AOL>, I say "it", exception when I don't mention it at all:
s/milk/real/g for @teeth;
Makeshifts last the longest. | [reply] [d/l] |