Thanks I understand what you're saying.

If I could ask, which one of these would you use?

> &showargs;  #NOT this is the tricky

> &showargs();
> showargs;
> showargs();

thanks,
-rkl

> [EMAIL PROTECTED] asked:
>> Here's an excerpt about the & from orielly and what the heck
>> does it means:
>>
>> "...If a subroutine is called using the & form, the argument list is
>> optional. if ommitted, no @_ array is setup for the routine;
>> the @_ array at the time of the call is visible to subroutine instead."
>
> If in doubt, run a test ;-)
>
> #!/usr/bin/perl -w
>
> use strict;
>
> sub showargs {
>   print "arguments are: " . join(', ', @_) . "\n";
> }
>
> sub test {
>   print "Arguments for test() are: " . join(', ', @_) . "\n";
>   print "Calling &showargs - ";
>   &showargs;
>   print "Calling &showargs() - ";
>   &showargs();
>   print "Calling showargs - ";
>   showargs;
>   print "Calling showargs() - ";
>   showargs();
> }
>
> test qw(foo baz bar);
> __END__
>
>> So, is there a better or worse? both ways works for me. I just started
>> going back and putting the & onto the sub ;) I don't like it
>> the & but I thought that you need it.
>
> See for yourself - there's only one use for the ampersand,
> and it's obscure. My advice would be to avoid using it even
> in the one situation where it would make sense - when passing
> @_ as an argument to your function. Sure, it is idiomatic Perl
> at its best, but it also makes a program harder to read and
> understand.
>
> In other words - save it for Perl Golf ;-)
>
> HTH,
> Thomas
>
> PS: Perl Golf - writing code with as little (key-)strokes as
> possible.
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to