On Apr 29, 4:57 am, shawnhco...@gmail.com (Shawn H Corey) wrote: > Akhthar Parvez K wrote: > > Hi, > > > The following line stores the first return value by the function Function1 > > to the variable $name: > > > my ($name) = @_[0] = &Function1 ($arg); > > > but this one doesn't work: > > my ($name) = $_[0] = &Function1 ($arg); > > > Eventhough I've no issues to use the first one as long as it works well for > > me, but I'm getting the following warning: > > Scalar value @_[0] better written as $_[0] > > > I hate warnings, but how can I fix that? As I said, $_[0] doesn't work. Can > > someone shed some light on this?
For a full explanation of the warning: perl -Mdiagnostics your_script.pl > > my ( $name ) = () = Function1( $arg ); > Um, that won't do what you think. The () just tosses all the return arg's and $name remains undefined because of the list context. my($name) = () = Function1($arg); # $name stays undef If $name were in scalar context though, you'd get a count of the arg's returned and thrown away by (): my $name = () = Function1($arg); # count of args to (); A couple of other alternatives: my ($name) = Function1($arg); my $name = ( Function1($arg) )[0]; -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/