[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] file tests



I feel like being charitable today.

At 14.00 -0500 1998.10.28, PwrSurge wrote:
>---BEGIN SCRIPT---
>foreach (@ARGV) {
>  $_ =~ s/.*:(.*)$/$1/;
>  $NAME = $1;

Since you are capturing $1 anyway, why bother doing a substitution?

   /.*:(.*)$/;
   $NAME = $1;

If you do what you did, then you lose the full path to the file and cannot
get the information about it.

Also, "$_ =~ s///" is always redundant.  Same with "$_ =~ m//".


>  $READ = "YES" if -r _;

_ only does a test on what you last did a test on.  If you have not yet
done a test, then _ is nothing.  You want $_.  On the other tests, then,
replace ITEM with _.

>  $WRITE = "YES" if -w ITEM;
>  $EXEC = "YES" if -x ITEM;
>  $KIND = "FLDR" if -d ITEM; elsif $KIND = "FILE";

This is a syntax error.  Maybe:

   $KIND = -d _ ? "FLDR" : "FILE";

Note also that if the value of all of these is undef, '', or 0, then the
value will carry over from the previous item.  i.e., if one file is
executable, then the next file will be noted as executable, even if it is
not:

MacPerl                              YES   YES  YES FILE 1439048  46.0739004629
Somefile.txt                         YES   YES  YES FILE    36    8.14099537037

Since you cannot make them lexical and still have write() see them, use the
?: operator again, as above with $KIND:

  $READ = -r $_ ? "YES" : "NO";
  $WRITE = -w _ ? "YES" : "NO";
  $EXEC = -x _ ? "YES" : "NO";


>  $SIZE = -s ITEM;
>  $LASTMODIFIED = -M ITEM;
>  write;
>}




>$NAME,$READ,$WRITE,$EXEC,$KIND,$SIZE,$LASTMODIFIED

I think these should probably be separated by spaces and have lowercase,
but that is personal style preference.  My new script (with #perl -w at the
top!):

#!perl -w
foreach (@ARGV) {
  /.*:(.*)$/;
  $name = $1;
  $read = -r $_ ? "YES" : "NO";
  $write = -w _ ? "YES" : "NO";
  $exec = -x _ ? "YES" : "NO";
  $kind = -d _ ? "FLDR" : "FILE";
  $size = -s _;
  $lastmodified = -M _;
  write;
}
format STDOUT_TOP =

NAME                                READ WRITE EXEC KIND   SIZE   LAST MODIFIED
------------------------------      ---- ----- ---- ---- -------- -------------
.

format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<      @>>> @>>>> @>>> @>>> @||||||| @>>>>>>>>>>>>
$name, $read, $write, $exec, $kind, $size, $lastmodified
.

--
Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/
%PGPKey = ('B76E72AD', [1024, '0824090B CE73CA10  1FF77F13 8180B6B6'])

***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch