Here is some commented code for you to perform what you were aiming for with your pseudo code. Set the $base_dir var and it will run as is.

cheers

tachyon

#!/usr/bin/perl -w use strict; # specify the full path to the image files in $base_dir # do not use \ on win32 use / Perl will convert like magic! # \ is the escape char. Just *don't use it* for paths # use / and let Perl take care of the conversion. my $base_dir = 'c:/windows'; # first let's just read all the files in the dir # and print them out, this is how we do it: opendir (DIR, $base_dir) or die "Unable to open dir: $base_dir Perl sa +ys: $!\n"; while (my $file = readdir DIR) { print "found file $file\n"; } closedir DIR; # OK so now we can read all the files in a dir # we can look at doing stuff with them. # What we do is to stuff the files into the # arrays you wanted using "push" # we push them into the array if they match # the criteria you seem to want # Note that within a match m/ / the . char has a special # meaning (it matches any single char) so to match a # literal . we "escape" it with a backslash (backwhack) my (@image4by6, @screenres, @thumbnail); # pacify strict opendir (DIR, $base_dir) or die "Unable to open dir: $base_dir Perl sa +ys: $!\n"; while (my $file = readdir DIR) { push @image4by6, $file if $file =~ m/4 by 6\.tif/; push @screenres, $file if $file =~ m/screen res\.tif/; push @thumbnail, $file if $file =~ m/thumbnail\.jpg/; } closedir DIR; # now lets print out our sorted arrays # via a function that we define (a subroutine) print "\n\nImage4by4 array contains:\n"; print_sorted( @image4by6 ); print "\n\nScreenres array contains:\n"; print_sorted( @screenres ); print "\n\nThumbnail array contains:\n"; print_sorted( @thumbnail ); exit; # this sub takes one argument - an array # the array is passed to the sub in the # magical @_ array. We sort this array # storing the result in @sorted # we then use a loop to iterate over # each element assigning it to $file # we print each file in turn plus a newline \n sub print_sorted { my @sorted = sort @_; foreach my $file (@sorted) { print "$file\n"; } }

In reply to Re: A monk in training with a problem by tachyon
in thread A monk in training with a problem by wiz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.