I find it hard to believe that there is no simple way for a function to return an empty list and bind this to a Perl array. In other words this code:
sub x { (); } @x = x(); use Data::Dumper; warn Dumper([\@x]);
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:
@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:
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 ; }

# ... and then later:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.