foreach $i (@dir) {
my @title = split /\./, $dir[$i];
$i is your file name so split that not the @dir entry. You're sort of trying
the same thing twice. foreach gets each array element, one at a time - you're
split usage implies you're expecting the array's index (also the var. name $i so
foreach $filename (@dir) {
is better and really
foreach my $filename ( @dir ) {
to be strict safe. You can also split right to a list of vars
my ($name, $ext) = split /\./, $filename;
Note I'm assuming the file have only one period. You may want to look at the
file name modules
File::Basename
File::Spec
and maybe the non-core (needs to be added via cpan or ppm)
Path::Class
See "Learning Perl" page 194-196
a
Andy Bach
(608) 658-1890
Not at my desk
On Jun 11, 2012, at 8:50 PM, Zheng Du <[email protected]> wrote:
>
> foreach $i (@dir) {
> *#$i here refers to each content of your array @dir, which are file names*
> my @title = split /\./, $dir[$i];
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/