JupiterHost.Net am Mittwoch, 8. Februar 2006 15.51:
> > use strict; # forces declaring variables
> > use warnings;
>
> yep yep :)
>
> >>@cpv_codes=('a','a','a','a','b','b','b','c','c','d');
> >
> > my @letters=(qw{ a a a a b b b c c d });
>
> No neeed for the (), which also make sit easier to write and to look at :)
Nice, I never considered omitting the (), thanks :-)
[...]
> > $hash{$_}++ for @letters;
>
> Good point, better than the map{} I just sent
>
> > print map "$_\t$hash{$_}\n", sort keys %hash;
>
> Not sure why you're using map here?
because print is only called once and not for every iteration.
Look at the following benchmark:
use strict;
use warnings;
use Benchmark;
my @words='word' x 100000;
timethese(10000000, {
'for' => 'print $_ for @words;',
'map' => 'print map {$_} @words;'
});
Benchmark: timing 10000000 iterations of for, map...
for: 14 wallclock secs ( 9.18 usr + 0.00 sys = 9.18 CPU) @
1089324.62/s (n=10000000)
map: 5 wallclock secs ( 3.55 usr + 0.02 sys = 3.57 CPU) @
2801120.45/s (n=10000000)
> print "$_\t$hash{$_}\n" for sort keys %hash;
>
> Also since strict and warnings have been recommended I might also poitin
> outthat %hash is a *very* bad name for a hash, its very ambiguouse and
> hard to maintain,
Why is %hash a very bad name?
Is @array also a bad name?
And what's the relationship with using strict and/or warnings?
> The entire thing is clearly written as:
[...]
greetings
joe
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>