Raymond Wan <r....@aist.go.jp> writes:

>
> Did you change the lstat to stat like I suggested in my first post?
> Are they files or symbolic links?

The problem seem to have been solved... see my reply to John K.

But to answer your question there... I did try it both ways.  It works 
with either lstat or stat, at least on the limited selection
I used. (two ascii text files and one symlink).

But does give different output:

 (t1 has been dressed up a little to give nicer output)
 Here it is with lstat
 cat ./t1
  #!/usr/local/bin/perl
  use strict;
  use warnings;

  my $mode;
  while(<>){
    chomp;
    $mode = (lstat( $_))[2];
    printf "File: %12s %s\n", "$_: mode", "<$mode>";
  } 

Here we see common files and a symlink
ls -l one two three
   -rw-r--r-- 1 reader reader 5 Mar 16 15:54 one
  lrwxrwxrwx 1 reader reader 3 Mar 18 15:09 three -> two
  -rw-r--r-- 1 reader reader 5 Mar 16 15:54 two
   
Now the ouput:
  ls one two three | ./t1     
  File:    one: mode <33188>
  File:  three: mode <41471>
  File:    two: mode <33188>

-------        ---------       ---=---       ---------      -------- 

Here we are with stat

cat t1
  #!/usr/local/bin/perl
  use strict;
  use warnings;

  my $mode;
  while(<>){
    chomp;
    $mode = (stat( $_))[2];
    printf "File: %12s %s\n", "$_: mode", "<$mode>";
  }

And our output:

 ls one two three | ./t1
  File:    one: mode <33188>
  File:  three: mode <33188>
  File:    two: mode <33188>
 
Apparently stat resolves the symlink and just reports its target

Side by side:

    With lstat                     With stat
    File:  three: mode <41471>     File:  three: mode <33188>


-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to