in reply to File globbing to a different directory

The following is untested. Does this answer your question?
# Assign path to $somedir opendir DH, $somedir or die "Cannot open $somedir: $!"; my @photos = grep { /\.jpg$/i } readdir DH; closedir DH;

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: (Ovid - reading files) Re: File globbing to a different directory
by nysus (Parson) on Apr 25, 2001 at 02:21 UTC
    That did the trick...you are a Perl God in my book. I'll have to study those opendir and readdir functions. But I'm wondering: do you know why my approach failed?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar";
    $nysus = $PM . $MCF;

      I have no idea why your approach failed. It looked fine to me. Now that I stop to think about it, I can't see why mine would have worked when your's failed. The benefit of using opendir is that it assigns to $! when it fails. File globs and the glob function don't do that (at least, not that I'm aware of).

      Side note: it's considered cleaner to check for files using the glob function instead of the file globbing operator. I should have suggested that first.

      When you said that it failed, how did it fail? Was there anything populating your @photos array?

      Cheers,
      Ovid

      Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Exactly, there was nothing in the array. I didn't get any errors either.

      $PM = "Perl Monk's";
      $MCF = "Most Clueless Friar";
      $nysus = $PM . $MCF;