At 03:14 -0500 12/03/2011, Uri Guttman wrote:

this replaces the entire if/else statement:

        $hash{$item}++ ;

...it is a standard perl idiom you need
to know so you don't waste code like that.

Nice!

so

#!/usr/local/bin/perl
use strict;
my %hash;
my @array = split //, 12342312111467;
for (@array){
  $hash{$_}++
}
for (sort keys %hash){
  print "$_ - $hash{$_}x\n"
}


1 - 5x
2 - 3x
3 - 2x
4 - 2x
6 - 1x
7 - 1x

JD

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to