SPUG: Minimal Perl talk at UW on Thursday

John W. Krahn krahnj at telus.net
Wed Nov 15 02:31:18 PST 2006


Tim Maher wrote:
> 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!

I just looked at the new listfiles on your site and I have one more comment
that I forgot the last time:


>         $target and $listing.=sprintf " $symbol $target";


There is no need to use sprintf() and that may break[1] depending on the
contents of $target and the version of Perl.

        $target and $listing .= " $symbol $target";


1)
http://groups.google.com/group/perl.perl5.porters/browse_frm/thread/a523b310487aa709?lnk=st&rnum=9

http://groups.google.com/group/perl.perl5.porters/browse_frm/thread/8fdae8a2372fa9ce?lnk=st&rnum=1

http://groups.google.com/group/perl.perl5.porters/browse_frm/thread/45ccc5bbb3c03e5b?lnk=st&rnum=1



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






John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.       -- Larry Wall


More information about the spug-list mailing list