[Chicago-talk] Wildcarding files on readdir
Jim Jacobus
JJacobus at PonyX.com
Mon Jul 24 20:49:20 PDT 2006
I'm trying to figure out how to create a string that will enable me
to read selective files in a directory with a wildcard. In other
words I'm trying to do a function line "dir *0.jpg" (which would get
all jpg files that end in zero). Closest I've got is:
-------------------------
main {
zardoz("*0.jpg");
}
sub zardoz {
$myfile = $_[0];
$my_files =~ s/\*/\./; # change asterisk to Perl's "." (any) ---> ".0.jpg"
opendir(THISDIR, "\.");
my @allfiles = grep /$my_files/, readdir(THISDIR);
closedir(THISDIR);
...
}
--------------------------------
which doesn't work very well. Converting "*" to ".' seems right, but
the period between the file name and extension seems to confuse me.
More information about the Chicago-talk
mailing list