At 06:06 AM 12/6/05, Jennifer Garner wrote:
I have a small script,when it run,it generate much more lines and put them
into a file.
The code for printing I writed:
map { print RESULT $_,":",$ips{$_},"\n" }
sort { $ips{$b} <=> $ips{$a} } keys %ips;
Certainly, I can write that code with foreach style.
I want to know which method is more effective between foreach and map?
I had basically the same question in October, with different code - check
the archives (subject was "map/array performance"). I was told not to use
"map" in void context ("map" has a return value and you aren't using it in
this context). With my code, I found using "foreach" was slower than
"map", but YMMV - do your own timings to see how it works for you. Someone
was gracious enough to show me alternate code that used array operators to
accomplish the same thing faster than both "map" and "foreach". Perhaps
you can adapt it to your situation. Sorry, I cannot.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>