Ron Smith wrote:
my @basenames = &basenames(@paths);
sub basenames { foreach (@_) { if ($_ =~ /(\w+)\.\d+\.\w+$/) { @basenames = $1; # print "@basenames\n";
That line assigns to @basenames the extracted basename from the last path only, i.e. the basenames extracted during previous iterations are not kept. You probably mean:
push @basenames, $1;
} }
Here the loop is finished, but nothing is returned from the subroutine.
return @basenames;
Actually, something IS returned, it is just not something that the OP expects or wants.
$ perl -e'
sub basenames {
for ( @_ ) {
if ( /(\d+)/ ) {
@basenames = $1;
}
}
}
my @basenames = basenames( @ARGV );
print @basenames . ": >" . join( "<, >", @basenames ) . "<\n";
' 123 456 789
1: ><John -- use Perl; program fulfillment
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
