in reply to Re: Empty List miracle(1)
in thread Empty List miracle(1)
There's no default.
If you say there's such a thing as a list in scalar context, it's because you're talking about list literals or the list operator. If so, the only behaviour for a list in scalar context is to return its last element after evaluating it in scalar context. undef is returned for empty lists.
# List literal in list context >perl -E"sub c { @a=qw(d e f g); @a } say('a', 'b', c())" abdefg # List literal in scalar context >perl -E"sub c { @a=qw(d e f g); @a } say(scalar('a', 'b', 'c'))" c # List literal in scalar context >perl -E"sub c { @a=qw(d e f g); @a } say(scalar('a', 'b', c()))" 4 # scalar(@a)
|
|---|