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

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.downloadsquad.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to