Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   what does underscore stands for ? (http://www.velocityreviews.com/forums/t899861-what-does-underscore-stands-for.html)

alpha_beta_release 09-11-2006 06:37 AM

what does underscore stands for ?
 
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.


alpha_beta_release 09-11-2006 08:13 AM

Re: what does underscore stands for ?
 
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 Dondi wrote:
> On 10 Sep 2006 23:37:48 -0700, "alpha_beta_release"
> <youknows@gmail.com> wrote:
>
> >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,



alpha_beta_release 09-11-2006 08:26 AM

Re: what does underscore stands for ?
 
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 Dondi wrote:
> On 10 Sep 2006 23:37:48 -0700, "alpha_beta_release"
> <youknows@gmail.com> wrote:
>
> >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,



Josef Moellers 09-11-2006 08:55 AM

Re: what does underscore stands for ?
 
alpha_beta_release wrote:
> 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,
--
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett


Aaron Sherman 09-11-2006 02:09 PM

Re: what does underscore stands for ?
 

alpha_beta_release wrote:

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



All times are GMT. The time now is 05:03 PM.

Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57