On 10/11/06, Moon, John <[EMAIL PROTECTED]> wrote: > perl -e '@a=("frc.apmt","frc_ff.apmt");print join(q{,}, map(&subt($_), > @a)), "\n"; > sub subt {my ($a) = @_; $a=~s/^(.*)\..*/$1/; print "a=$a\n"; > return $a;}' > perl -e '@a=("frc.apmt","frc_ff.apmt");print join(q{,}, > map(s/^(.*)\..*/$1/, @a)), "\n"; ' > perl -e '@a=("frc.apmt","frc_ff.apmt");print join(q{,}, > map(s/^(.*)\..*/\1/, @a)), "\n"; ' > > Can someone explain why the last two examples don't product the same > output as the first? > > Thank you in advance. > jwm
>>Sure. It's the first par of the sub: >> >> my $a = @_; >> >>In scalar context, an array returns the number of elements, so your $a >>gets 1. Even though you only pass your sub 1 item, @_ is still an >>array. It's a 1-element array, but it's an array. What you want is: >> >> my $a = shift @_; >> >>Also, for future reference using $a and $b is dangerous and considered >>bad form; Perl uses them internally to implement sort. >> >>HTH Thank you for looking but first part of sub is: my ($a) = @_; and the first test script is returning what I want ... it's the second & third I'm asking about jwm -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>