Akhthar Parvez K wrote:
On Thursday 29 Apr 2010, Shlomi Fish wrote:
Why are you assigning to variables inside @_? It's almost always a bad idea.
@_ is the function parameters' list. You should read the values from there
(using "my ($param1, $param2, $param3) = @_;" or "my $param1 = shift;" (short
for "shift(@_)")) and then possibly mutate them if they are references and
return values from the function using return.
Well, I know that @_ is a list with arguments passed to the function. But I thought it also stores the
"return" values from a subroutine. eg:- If Function1 returns "abc" and "pqr" and I want
to catch only the first return value ("abc" in this case), I could use the following line:
my ( $name ) = ( $_[0] ) = Function1( $arg ); (Thanks to John and Shawn for
correcting me with that)
Anything wrong with this method? If so, what's the correct method then?
It overwrites the first element of @_. Use this instead:
my ( $name ) = () = Function1( $arg );
--
Just my 0.00000002 million dollars worth,
Shawn
Programming is as much about organization and communication
as it is about coding.
I like Perl; it's the only language where you can bless your
thingy.
Eliminate software piracy: use only FLOSS.
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/