what does underscore stands for ?

A

alpha_beta_release

HI

what does underscore stands for ?
e.g. get file modification time, someone write like this
-M _

what i understand is it's treated as bareword (filehandle and labels).
Is it default filehandle, like $_ (for scalar)?
or maybe i'm wrong. I need some explanation...

Thanx in advance.
 
A

alpha_beta_release

ok. thanx. actually i've gone through this section, and forgot to
mention about the solitary underscore ;) but what i need is the
explanation about this special filehandle _. What it's purpose?

Michele said:
what does underscore stands for ?
e.g. get file modification time, someone write like this
-M _

Check

perldoc -f -X

towards the end.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
A

alpha_beta_release

ok. i understand something.

What i found is that if we provide this '_' to the second (and
subsequent) file test operations (-M, -f etc), the result returned is
from the first test operation. Am i correct?
e.g.
-f $somefile;
-M _ ; # use the result of above operation

-t $somefile; # fresh call
-M _ ; # use the result of above operation

Actually i found this in Dir::purge.pm, makes me wonder for while. It's
no very clear at first. Anyway thanks Michele for the pointer.

Michele said:
what does underscore stands for ?
e.g. get file modification time, someone write like this
-M _

Check

perldoc -f -X

towards the end.


Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
 
J

Josef Moellers

alpha_beta_release said:
ok. i understand something.

What i found is that if we provide this '_' to the second (and
subsequent) file test operations (-M, -f etc), the result returned is
from the first test operation. Am i correct?
e.g.
-f $somefile;
-M _ ; # use the result of above operation

-t $somefile; # fresh call
-M _ ; # use the result of above operation

It uses an _internal_ _intermediate_ result from the previous operation.

When you do "-f $somefile", then the fact that $somefile is or is not a
plain file does not appear out of thin air but the perl runtime has to
perform a "stat" operation on $somefile which returns muchmuch more than
just an indicator on the file type (see perldoc -f stat), so it is an
optimization to keep the internal result of the internal stat operation
for later reference.
"-M _" will then not have to do a new "stat" but can just pick up the
modification time from the data returned by the "stat" done for the "-f
$somefile".

HTH,
 
A

Aaron Sherman

alpha_beta_release said:
-f $somefile;
-M _ ; # use the result of above operation
Actually i found this in Dir::purge.pm, makes me wonder for while. It's
no very clear at first. Anyway thanks Michele for the pointer.

It's clear if you understand the idioms of Perl, and not if you don't,
much the way casting to a function pointer looks like line noise in C
unless you understand that this is a common idiom, recognize it and
move on. The only difference is that Perl's idioms tend to hold more
semantic weight in fewer symbols.

_ in Perl is the sort of all-around tool meaning "default" or "supplied
input". It has different contexts:

_ - stat-operation default (last stat block)
$_ - Default value stored to and read from by many operations. Also
used as a temporary
@_ - Parameter list to a subroutine

Personally, I've always thought _ should also be a label, such that
"next _" would always select the outermost loop, similar to the way
"next" without a parameter selects the innermost.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top