Help for this page

Select Code to Download


  1. or download this
    my %freq;
    for my $i ( 1 .. @data ) {
        $freq{ $1 }[ $-[0] ] += 1/@data while $data[ $i-1 ] =~ /(.)/g;
    }
    
  2. or download this
    my $inc = 1 / @data;                                       ## do the i
    +nvariant once:
    for ( @data ) {                                            ## $_ alias
    +es each line in turn avoids both the $i-1 and indexing the array
        $freq{ $1 }[ $-[0] ] += $inc while /(.)/g;             ## the rege
    +x engine operates directly on the $_ alias.
    }
    
  3. or download this
    for( @data ) {                                 ## use $_ to alias the 
    +lines
        my $p = -1;                                ## Allow pre-increment 
    +which is more efficient
        $freq{ chop() }[ ++$p ] += $inc while $_;  ## implicit arg for cho
    +p; avoid call to length.
    }