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

> Hi Harry,
>
>
> Raymond Wan wrote:
>> The other option is to *not* use ls and get your script to stat the
>> file directly (NB:  I guess you want stat and not lstat?).  In this
>> case, you should get a list of files in the directory, and then run
>> stat on each one.  If you do this (which is perhaps the better
>> option), you would want to look up the readdir command, in addition
>> to stat.

But, the end result with either `ls -1 (numeric one)' or something
like. (From perldoc -f readdir)

  @dots = grep { /^\./ && -f "$some_dir/$_" } readdir($dh);
  closedir $dh;

Is the same thing... a list of file names.  Only above they have been
verified by the -f test.

and of course that does what I want... but still being puzzled by the
failure of the original script.

> Sorry, slight correction to what I said as I just realized what you
> were doing :-) ...  If you are using ls to feed the list of files,
> then maybe your problem is how you ran "ls"?  Perhaps you should use
> the "-1" option to ensure one file is on each line?

Yeah, I should have mentioned that... .  I did try that and have 
replied to Shlomi showing output having used ls -1 (numeral one)

I don't really think it matters though.  I see the script, though it
fails does print `$_' as 1 file name whether `ls -1' or plain `ls' is
fed in.

For example... if we remove the stat part like this:

  #!/usr/bin/perl

  use strict;
  use warnings;

  while(<>){
     print "$_\n";
  }

The result of either `ls' or `ls -1' is the same.

 ls *.txt|./t3
 msg-on-share_nfs.txt
 msg-on-share_nfs2.txt

 ls -1 *.txt|./t3
 msg-on-share_nfs.txt
 msg-on-share_nfs2.txt



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