Steve Grazzini <[EMAIL PROTECTED]> writes:

> Harry Putnam <[EMAIL PROTECTED]> wrote:
>> "Janek Schleicher" <[EMAIL PROTECTED]> writes:
>>>
>>> The underscore _ holds the results of the last stat call 
>>> (implicitly called by the -f operator), so no unnecessary 
>>> work needs to be done.
>> 
>> I've seen that `_' crop up before
>> I don't understand what this means.
>
> It's documented in perlfunc:

Yes, I saw it there too.  I must be having a particularly dense time
of it, but I still am missing what is actually in _

>     $ perldoc -f stat
>         [ snip ]
>
>         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 previous content of the stat structure is what? (in plain english)
Does it mean the previous values of the 13 elements produced by stat?
Or something else...

     if (-e $file and -f _) { ...

What is -f being tested against.  If not $file then what... 

The
 ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
   $atime,$mtime,$ctime,$blksize,$blocks)
Resulting from the -e test?

Or getting back to original question... 
perl -e '$mode = (stat($ARGV[0]))[2];print "$mode\n";' test.f
33204

What is it about 33204 that tells us `type' is a regular file
The first digit being 3?
 perl -e '$mode = (stat($ARGV[0]))[2];print "$mode\n";' test.d     
16893
  "ditto  regular directory"
The first digit being 1?

That is, might one just look for a static part of $mode to know the
type?

perldoc -f stat seems to indicate it might?

[...]
            0 dev      device number of filesystem
            1 ino      inode number
            2 mode     file mode  (type and permissions)
[...]

And a few tests with this:
#!/usr/local/bin/perl -w

for(@ARGV){
   chomp;
  $mode = (lstat($_))[2];
  if ( $mode =~ /^3/){
    print  "$mode $_: Regular file\n";
  }elsif($mode =~ /^1/){
    print "$mode $_: Directory\n";
  }elsif($mode =~ /^41/){
    print "$mode $_: Symlink\n";
  }
}

Seem to indicate it will work.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to