2011/2/10 terry peng <terry.p...@mail.ru>: > does "return ()" mean return an empty list, or just mean "return" since "()" > is optional in Perl?
I would have guessed an empty list, but the best way to find out is to check. :) According to my tests, it's returning according to context: #!/usr/bin/env perl use strict; use warnings; use Data::Dumper; sub test1 { return (); } sub test2 { return; } sub test3 { my @empty_array = (); return @empty_array; } my $scalar1 = test1; my $scalar2 = test2; my $scalar3 = test3; my @array1 = test1; my @array2 = test2; my @array3 = test3; print "\$scalar1: ", Dumper \$scalar1; print "\$scalar2: ", Dumper \$scalar2; print "\$scalar3: ", Dumper \$scalar3; print "\@array1: ", Dumper \@array1; print "\@array2: ", Dumper \@array2; print "\@array3: ", Dumper \@array3; __END__ Results: $scalar1: $VAR1 = \undef; $scalar2: $VAR1 = \undef; $scalar3: $VAR1 = \0; @array1: $VAR1 = []; @array2: $VAR1 = []; @array3: $VAR1 = []; So it seems the only time an empty list is returned in scalar context is when I returned an empty array. I think that `return ();` is returning undef in scalar context, just as `return;` does. -- Brandon McCaig <http://www.bamccaig.com/> <bamcc...@gmail.com> V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> <bamcc...@castopulence.org> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/