You posted this code:
use warnings; use strict; use File::Basename; my @extens = qw(.zip .dmg .tar.gz .pl .pl~ .cgi .mp3 .txt); my @ppal; my $i = 0; foreach my $arch (@ARGV ){ my ($name,$path,$suffix) = fileparse($arch,@extens); $ppal[$i] = []; push @{$ppal[$i]},($path,$name,$suffix); $i++; } foreach my $elem (@ppal){ print "Path:\t@{$elem}[0]\tArchivo:\t@{$elem}[1]\tExtens:\t@{$elem +}[2]\n"; }
It could use some cleanup:
use warnings; use strict; use File::Basename; my @extens = qw(.zip .dmg .tar.gz .pl .pl~ .cgi .mp3 .txt); my @ppal; foreach my $arch (@ARGV) { push @ppal, [ fileparse($arch, @extens) ]; } foreach my $elem (@ppal) { print "Path:\t${$elem}[0]\tArchivo:\t${$elem}[1]\tExtens:\t${$elem +}[2]\n"; #or: print "Path:\t$elem->[0]\tArchivo:\t$elem->[1]\tExtens:\t$ele +m->[2]\n"; #or: printf "Path:\t%s\tArchivo:\t%s\tExtens:\t%s\n", @$elem; }
To introduce map, change
tomy @ppal; foreach my $arch (@ARGV) { push @ppal, [ fileparse($arch, @extens) ]; }
my @ppal = map { [ fileparse($_, @extens) ] } @ARGV;
In reply to Re: Complex structures and function "map"
by ikegami
in thread Complex structures and function "map"
by nando
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |