On Wed, Sep 04, 2002 at 09:41:54PM +0200, Fabian Funk wrote:
> Hi, I'm pretty new to perl. I want to open a Directory with mp3 files an
> other files. My Poblem is i need only the mp3 files. How can i get only
> the mp3 files and not other files ?
>
> I tried:
>
> while (defined(my $file=readdir(DIR))) {
Here you assign to $file...
> next if $file=~ /^\.\.?$/;
....and here you use it...
> next unless /\.[mp3]$/i;
....but here you use $_ instead.
Besides that, you're matching all files *.m, *.p and *.3. Match for
/\.mp3$/ instead.
> push(@files,$file);
>
> But i get "Use of uninitialized value in pattern match (m//)
> What's wrong ???
That was the match on $_ which hadn't been set.
BTW: perldoc -f readdir has a pretty good example for what you need to
do.
Try replacing your whole while construct with
my @files = grep { -f $_ && /\.mp3$/ } readdir DIR;
--
Well, then let's give that Java-Wussie a beating... (me)
Michael Lamertz | +49 2234 204947 / +49 171 6900 310
Sandstr. 122 | [EMAIL PROTECTED]
50226 Frechen | http://www.lamertz.net
Germany | http://www.perl-ronin.de
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]