J
Jason Mather
Several places in File/Find.pm there are tests like:
if (-d _) {
What is '_'? Is it the same as '$_'?
-- Jason
if (-d _) {
What is '_'? Is it the same as '$_'?
-- Jason
"Jason Mather" said:Several places in File/Find.pm there are tests like:
if (-d _) {
What is '_'? Is it the same as '$_'?
Perldoc -f -x (-x is the function name eh?)
at the end, all the gory details, and examples.
Randal L. Schwartz said:Richard> When you get perl to stat a file (ie you ask perl for
Richard> information about the file, eg is it a directory, how long is
Richard> the file, what is its mod time, etc) perl uses a system
Richard> function called stat, which returns a lot of information
Richard> about the file. The results of the stat are cached. The '_'
Richard> causes perl to consult the stored stat results instead of
Richard> statting the file again.
Yup. One of the few features of Perl I can claim to have invented.
Two others that come to mind are the literal-slice notation and the
use of arrow for dereferencing code refs. And the JAPH.
Richard> When you get perl to stat a file (ie you ask perl for
Richard> information about the file, eg is it a directory, how long is
Richard> the file, what is its mod time, etc) perl uses a system
Richard> function called stat, which returns a lot of information
Richard> about the file. The results of the stat are cached. The '_'
Richard> causes perl to consult the stored stat results instead of
Richard> statting the file again.
Yup. One of the few features of Perl I can claim to have invented.
Two others that come to mind are the literal-slice notation and the
use of arrow for dereferencing code refs. And the JAPH.
print "Just another Perl hacker,"
Sara said:Curious, just consulted Camel v3, don't see this documented, or at
least if its there, it's not obvious. Is it a secret only revealed to
newsgroup readers?
Bart Lateur said:I think it's in perlfunc, under "stat".
If stat is passed the special filehandle consisting of an
underline, no stat is done, but the current contents of the stat
structure from the last stat or filetest are returned.
It's a good place to find out about it, when you're checking out stat(),
but the reverse, looking up what "_" means, isn't obvious -- as shown
here.
John> Yes, but what have you done lately?
In general, they don't need me. That's nice. I can focus on
cranking out 2.5 columns a month and managing my micro-herd of Perl
trainers and consultants.
Curious, just consulted Camel v3, don't see this documented, or at
least if its there, it's not obvious. Is it a secret only revealed to
newsgroup readers? Nice to know though thanks!
G
p> sub routine
p> {
p> my $file = shift;
p> if ( -e $file )
p> {
p> # do something
p> return;
p> }
p> if ( -d $file )
you can use _ there.
p> if ( function() )
p> {
p> # do something else
p> return;
p> }
p> }
p> sub function { return -f _; }
if nothing has done a stat or -X since the previous one on $file, then
you are ok. but i wouldn't trust your code to not do that. _ is
basically an operator but it acts like a global variable with no
scoping. i would never use it outside the immediate area which had
the original stat call.
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.