Re: array iteration problem

2006-02-08 Thread John Doe
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

Re: array iteration problem

2006-02-08 Thread Bjørge Solli
On Wednesday 08 February 2006 15:51, JupiterHost.Net wrote: > So for instance to treat upper and lowercase the same (IE 't' is > considered the same as 'T') > > for my $letter(@letters) { > $letter_count{ lc($letter) }++ if lc($letter) =~ m{^[a-z]$}; > } or just (untested): $letter_count{$_}+

Re: array iteration problem

2006-02-08 Thread JupiterHost.Net
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 :) # qw (quote words) makes it easier to write and to

Re: array iteration problem

2006-02-08 Thread JupiterHost.Net
Hello, and it prints: a1 a2 a3 a4 b1 b2 b3 c1 c2 d1 What I really need is: a = 4 b = 3 c = 2 d = 1 > How would I do this? Any ideas? You're printing each time its incremented, just print the keys and their

Re: array iteration problem

2006-02-08 Thread John Doe
Graeme McLaren am Mittwoch, 8. Februar 2006 14.53: > Hi all, I have the following code: Hi Graeme > # code use strict; # forces declaring variables use warnings; > @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 }); # qw (

Re: array iteration problem

2006-02-08 Thread Jeff Pang
>foreach (@letters) { >$hash{$_}++; >print "$_\t $hash{$_} \n"; >} I think,the code should be written as below: foreach (@letters) { $hash{$_}++; } foreach (sort keys %hash){ print "$_ = $hash{$_} \n"; } -- Jeff Pang NetEase AntiSpam Team http://corp.netease.com -- To unsu

array iteration problem

2006-02-08 Thread Graeme McLaren
Hi all, I have the following code: # code @cpv_codes=('a','a','a','a','b','b','b','c','c','d'); my %hash; foreach (@letters) { $hash{$_}++; print "$_\t $hash{$_} \n"; } and it prints: a1 a2 a3 a