On Mon, 25 Sep 2000 10:19:05 +0100, Simon Cozens wrote:

>    (%alphabet) = $string =~ tr/a-z//;
>
>Yum.

You want it in a hash? Ooff. Well, maybe that's ok for Perl6.

For Perl5, it would seem to make more sense, to me, to return a list.
Simply a matter of consistency with the spirit of the rest of the
language.

        @frequency = tr/a-z//;

would stuff the results in:

        'a' -> $frequency[0] 
        'b' -> $frequency[1] 
...
        'z' -> $frequency[25]


If you want a hash, you can use the hash slice trick to build one
yourself:

        @frequency{'a' .. 'z'} = tr/a-z//;


And finally, you can get all the histograms you want, by doing:

        while(/([a-z])/g) {
                $count{$1}++;
        }

or

        s/([a-z])/$count{$1}++, $1/ge;

-- 
        Bart.

Reply via email to