Hi Nora, On Friday 30 Apr 2010 09:55:33 HACKER Nora wrote: > Hi, > > For calling subroutines and passing arguments on I use e.g. > > my ( $var1, $var2 ) = @_; > > If I have only one argument, this is also ok: > > my ( $var1) = @_; > > But why does > > my $var1 = @_; > > not work?
Because the lack of parenthesis signifies that the right-hand-side will be done in scalar context. As a result it is equivalent to: my $var1 = scalar(@_); Which is the length of the @_ array (which sometimes have some valid uses if you're checking for optional arguments but otherwise not what you want here.). If you do: my ($var1) = @_; You're doing list assignment and, as a result, you assign $var1 to the $_[0] and don't make use of $_[1], $_[2], $_[3], etc., which may or may not exist. > In 'perldoc perlsub' I read that I only have to use > parentheses when defining more than one variable. Where do you see that written? Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ My Aphorisms - http://www.shlomifish.org/humour.html God considered inflicting XSLT as the tenth plague of Egypt, but then decided against it because he thought it would be too evil. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/