shows that @x is bound to a list with one element. Every response above is kind of interesting. You all seem to be trying to protect Perl's hard-to-justify and far-from-intuitive return mechanisms. By golly, if I can do the following:sub x { (); } @x = x(); use Data::Dumper; warn Dumper([\@x]);
Then why doesnn't that transfer in a commonsense way to putting the () in a sub and returning it? Because of the way Perl is structured I have had to use the following voodoo:@x = ();
sub get_remote_listing { my $dir = $_[0]; $ftp::session->cwd($dir); $ftp::session->ls; } sub get_local_listing { my $local_dir=shift; opendir(DIR, $local_dir) || die "can't opendir $local_dir: $!"; my @files = grep { -f $_ } readdir(DIR); closedir DIR; \@files ; }
my $local = get_local_listing ( $assigned_dir ); print "local listing=@$local*****\n"; my @local = defined($local) ? @$local : (); my $remote = get_remote_listing $azx::auction{$A}->{ftp_dir}; my @remote = defined($remote) ? @$remote : ();
And you can't abstract the tests for defined-ness of the array reference into a subroutine unless you go a step further into Mystical and Esoteric Invocations in a Language Supposed to Support Laziness:
sub bind_aref { my ($aref,$target_aref)=@_; @$target_aref = defined($aref) ? @$aref : (); }
In reply to How does one return an Empty list as a return value
by princepawn
in thread Empty list as a return value
by princepawn
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |