in reply to Re^2: Can't understand function returning undefs
in thread Can't understand function returning undefs
But if we are at it. My problem is that I have a function that returns two values when data is available to it and when no data remained it returns undef.
It should return an empty list when no data remains. Compare
withmy @a = qw( a b c d ); my $i = sub { @a ? splice(@a, 0, 2) : () }; while (my ($x,$y) = $i->()) { print("$x:$y\n"); }
my @a = qw( a b c d ); my $i = sub { @a ? splice(@a, 0, 2) : (undef,undef) }; while (my ($x,$y) = $i->()) { print("$x:$y\n"); }
Update: Added missing semicolons.
|
|---|