in reply to Re: Re: whats wrong with my sub-routine ??
in thread whats wrong with my sub-routine ??
Some misunderstandings:
my $ar = qw/ foo bar baz /;In the line above, you're assigning a list in scalar context. You're going to get the last element of that list (baz) assigned to $ar.
func(\@ar);That will throw a warning under strict because you declared a scalar ($ar), not an array (@ar).
my $ar = @_;Now you're accessing an array in scalar context. This will result in $ar being set the the number of elements in @_. Here's a quick demonstration:
$ perl -e 'sub aa {my $a = @_;print $a}; aa(qw(foo bar baz))' 3
I realie those seem tricky and frankly, it's often a matter of memorizing how those things behave.
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re4: whats wrong with my sub-routine ??
by dragonchild (Archbishop) on Apr 23, 2003 at 17:17 UTC | |
by Ovid (Cardinal) on Apr 23, 2003 at 17:19 UTC |