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


in reply to Re: Trouble getting size of list returned from sub
in thread Trouble getting size of list returned from sub

Actually they all do that, they copy the list to the "stack", its just that map introduces a scope, by the time it ends, perl has a chance to release the memory it used back to the OS -- an optimization

For a long time map/grep in scalar/void context took double the memory than equivalent for loop, so depending on perl version memory usage will differ between these two lines

warn scalar grep {1} foo(); my $count = 0; $count++ for foo(); warn $count ;

wantarray is what you want to use if you want to be sure :)