bare underscore?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I was looking at the standard module, and saw this puzzling (to
me) bit:

foreach (reverse @_) {
    my $path = $_;        # we'll be modifying it, so break the alias
    if ($path eq '') {
        require Carp;
        Carp::carp("Empty compile time value given to use lib");

    $path = _nativize($path);

    if (-e $path && ! -d _) {
        require Carp;
        Carp::carp("Parameter to use lib must be directory, not file");

What does the _ with no sigil before it mean in
    if (-e $path && ! -d _) {



Mike Slass

Re: bare underscore?

Michael Slass wrote:
Quoted text here. Click to load it

perldoc -f -d
[ SNIP ]

         If any of the file tests (or either the "stat" or "lstat"
         operators) are 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=92t work with "-t", and you need to remember that lstat()
         and "-l" will 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 _;

             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 _;

Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.                            -- Larry Wall

Re: bare underscore?

Quoted text here. Click to load it

Thanks to both of you; I was looking in the perlvar manpage for a
magic variable; I hadn't guessed it was magic in the -d operator.

Thanks again,

Mike Slass

Site Timeline