in reply to Empty list as a return value

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
RE: How does one return an Empty list as a return value
by merlyn (Sage) on Oct 23, 2000 at 21:10 UTC
    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.
    No, it's not. Watch this:
    sub routine { return (); } @x = routine(); print 0+@x;
    This prints 0, as expected. You are handing to Data::Dumper a list of one item, that one item being a reference to your empty array. Stop indirecting so much!

    -- Randal L. Schwartz, Perl hacker

RE: How does one return an Empty list as a return value
by runrig (Abbot) on Oct 23, 2000 at 20:47 UTC
    What are you talking about?
    #!/usr/local/bin/perl -l -w use strict; use Data::Dumper; sub x { (); } my @x = x(); my $num = @x; print $num; for (@x) { print; } print Dumper (\@x, $num); #output: 0 $VAR1 = []; $VAR2 = 0;
    Update: You gave Dumper() a reference to an array with an element which was a reference to an empty array.