in reply to Read only Files in a Directory

I've used something akin to:

$base = '/usr/local/bin/'; @glob = grep { -f ($base . $_)} @glob;

to filter out everything which isn't a file (I did it on Windows, but -f is portable). glob is quite handy for this, although characters meaningful to csh must be escaped.


corrected really dumb spelling error.

emc

Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.

Groucho Marx

Replies are listed 'Best First'.
Re^2: Read only Files in a Directory
by Hue-Bond (Priest) on Aug 01, 2006 at 22:01 UTC
    characters meaningful to csh must be escaped

    Not in my experience (on a Unix, though):

    ## create some files with funny names map { open my $fd, '>', chr $_ or die "open: $!"; close $fd; } 33..45,58..63,91..96,123..126 $ perl -le 'print glob q[+]' + $ perl -le 'print glob q[`]' ` $ perl -le 'print glob q[;]' ;

    The only gotchas are * and ?:

    $ perl -le 'print glob q[?]' !"#$%&'()*+,-:;<=>?[\]^_`{|}~ $ perl -le 'print glob q[\?]' ? $ perl -le 'print glob q[*]' !"#$%&'()*+,-:;<=>?[\]^_`{|}~ $ perl -le 'print glob q[\*]' *

    --
    David Serrano

      Not in my experience (on a Unix, though):

      It is my experience on Windows: it gets confused about blanks in directory names, possibly because it's implemented differently in the Windows port than in the various *ixen.

      I don't know whether using opendir and readdir is better than glob, but I usually find glob more convenient.

      emc

      Outside of a dog, a book is man's best friend. Inside of a dog it's too dark to read.

      Groucho Marx