C.DeRykus wrote:
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 ();
Talk about inconsistent behaviour. In list context it modifies the list
as the assignments are made but in scalar context, it doesn't. Looks
like a bug to me.
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;
my $arg = 7;
my ( $n ) = () = Function( $arg );
print '1st: ', Dumper \$arg, \$n;
my ( $x, $y ) = ( $n ) = Function( $arg );
print '2nd: ', Dumper \$arg, \$n, \$x, \$y;
my $count = ( $n ) = Function( $arg );
print '3nd: ', Dumper \$arg, \$n, \$count;
sub Function {
return ( 3 .. $arg );
}
__END__
--
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: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/