On Wed, May 21, 2014 at 3:00 PM, Yossi Itzkovich <[email protected]> wrote: > Hi, > > > > Suppose I have a huge hash. when I write > > my $n= keys %hash; > > > > Will it consume time and RAM for building the unneeded list (before taking > the size from it), or will it return the size immediately ? > > If it does cost me a lot, can I optimize it ? >
The documentation does not say anything about this, and I am not sure, but I don't see a reason why in scalar context 'keys' would need to create an array in memory. In any case, I wonder why are you concerned? Have you encountered an issue with an application? If not, then just use it and if you encounter a problem then check if the source of the problem is this statement. Or write a script that does this with a huge hash and check the memory footprint. This could be a nice article. Or, if you really want to be sure, check the source code of perl. regards Gabor _______________________________________________ Perl mailing list [email protected] http://mail.perl.org.il/mailman/listinfo/perl
