http://www.perlmonks.org?node_id=1005594

wanna_code_perl has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I'll confess to feeling rather foolish right now. I have to work with a sub that is returning a list directly, and I don't need the contents of the list; just the number of elements, but I can't figure out how to do so without a temp variable. Here's a simplified example:

sub good { my @a = qw/zero one two/; @a } sub bad { qw/foo bar baz/ } say scalar good(), "\t<== what I want"; say scalar bad(), "\t<== not"; __END__ Output: 3 <== what I want baz <== not

I can accomplish what I want with this clumsy mess:

{ my @temp = bad(); say scalar @temp; }

Is there no way to avoid the temp variable? And will Perl actually create a copy of the list in that case? My typical solution set is in the thousands.

As for the sub itself, it's someone else's XS code that I'm loathe to modify (not just something I can stick a wantarray in...), but I will if absolutely necessary.