Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: Help with file test operators

by jeffa (Bishop)
on Mar 26, 2015 at 20:48 UTC ( [id://1121459]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Help with file test operators
in thread Help with file test operators

Try

perldoc -f -X

    If any of the file tests (or either the "stat" or "lstat" 
    operator) is given the special filehandle consisting of a solitary
    underline, then the stat structure of the previous file test (or
    stat operator) is used, saving a system call. (This doesn't work
    with "-t", and you need to remember that lstat() and "-l" leave
    values in the stat structure for the symbolic link, not the real
    file.) (Also, if the stat buffer was filled by an "lstat" call,
    "-T" and "-B" will reset it with the results of "stat _").
    Example:

        print "Can do.\n" if -r $a || -w _ || -x _;

        stat($filename);
        print "Readable\n" if -r _;
        print "Writable\n" if -w _;
        print "Executable\n" if -x _;
        print "Setuid\n" if -u _;
        print "Setgid\n" if -g _;
        print "Sticky\n" if -k _;
        print "Text\n" if -T _;
        print "Binary\n" if -B _;

UPDATE:
"... the point is that it's not obvious ..."

Just showing you where the information is currently found. If you want to make it more obvious you know exactly how to get that ball rolling on your own. Good luck.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^4: Help with file test operators
by LanX (Saint) on Mar 26, 2015 at 21:07 UTC
    > perldoc -f -X

    true, but the point is that it's not obvious to look in stat or perlfunc if one notices that _ behaves differently to other barewords.

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1121459]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (8)
As of 2024-04-19 07:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found