SPUG: Minimal Perl talk at UW on Thursday

Tim Maher tim at consultix-inc.com
Tue Nov 14 16:56:11 PST 2006


On Tue, Nov 14, 2006 at 02:37:12PM -0800, John W. Krahn wrote:
> 
> I hope you don't mind,  :-),  some comments on the listfiles script:

Be my guest!
 
> The file http://minimalperl.com/listfiles.plx appears to be HTML but
> because of the .plx extention it displays as plain text.

It was /supposed/ to be plain text; 'twas a Template Toolkit config 
error--thanks for spotting it!
 
> >         # Doesn't handle ls's -a, etc., so discard
> >         # hyphen-prefixed options, if any
> >         while ( defined $ARGV[0] and $ARGV[0] =~ /^-/ ) {
> >             warn "$0: Ignoring option: '$ARGV[0]'\n";
> >             shift;
> >         }
> 
> What if you have file names that begin with a '-' character?

** Then you deserve to have a difficult life! 8-{ **

The program is more interested in advising the user that it doesn't honor
the options of /bin/ls than it is in accommodating the existence of non-UNIXy
filename conventions.

Of course, you can always modify the program to suit your special
needs, if appropriate. (A "--" option to signify the end of options
could be added.)
 
> >         -e $filename or
...
> >         if (-l $filename) {  # file is a symlink
...
> >                 undef, $size, undef, $mtime)=stat $filename;
> 
> You are stat()ing the same file three times, why not just once:

That's a good point; I was delaying "optimization" until later
to avoid the well-known consequences of doing it prematurely--
but now might be a good time! 8-}

> >         $x=getgrgid $gid;
> >         defined $x and $x =~ /[a-zA-Z]/ and $gid_name=$x;
> 
> Is there some Unix or Posix specification that requires the /[a-zA-
> Z]/ test?
>
> Or to put it another way, if the test failed would that be proof
> that the name was invalid?

Not testing the filename there, but rather whether getgrgid
returned a numeric GID (meaning it failed to find the associated user-
name) or a verbal GID.  Probably should be simply: $x =~ /\D/

> John

Thanks for the input!
*-------------------------------------------------------------------*
|  Tim Maher, PhD  (206) 781-UNIX   (866) DOC-PERL  (866) DOC-UNIX  |
|  tim at ( Consultix-Inc, TeachMePerl, or TeachMeUnix ) dot Com    |
*-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-*
| Seattle Classes;  12/11 Shell Prog.   12/14: UNIX/Linux Utilities |
|  * Download free chapters from my new book at MinimalPerl.com *   |
*-------------------------------------------------------------------*


More information about the spug-list mailing list