Advertisements

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:urge.pm, makes me wonder for while. It's
no very clear at first. Anyway thanks Michele for the pointer.

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

alpha_beta_release wrote:
> -f $somefile;
> -M _ ; # use the result of above operation
> Actually i found this in Dir:urge.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.

Share This Page

Welcome to The Coding Forums!

Welcome to the Coding Forums, the place to chat about anything related to programming and coding languages.

Please join our friendly community by clicking the button below - it only takes a few seconds and is totally free. You'll be able to ask questions about coding or chat with the community and help others.
Sign up now!