The error in your code has been already pointed out by merlyn and somebody else (how fast are these people ;-), but I'd like to add a more "idiomatic" version of your code. You should return mp3 files only (if you are after them ;-) ...
#!/usr/bin/perl use strict; use warnings; use Carp; my $dir = '/home/musc'; my @mp3 = getSongs( $dir ); for my $song (@mp3) { print "$song\n"; } sub getSongs { my $dir = shift; my @files; if( -d $dir ) { opendir(my $dirhandle, $dir) or croak "$dir $!"; @files = grep /\.mp3$/, readdir $dirhandle; closedir $dirhandle } else { carp "don't know about $dir\n" } return @files; }
Regards
mwa
In reply to Re: subroutine array empty
by mwah
in thread subroutine array empty
by davidov0009
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |