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.
- RFC 283 (v1) C<tr///> in array context should re... Perl6 RFC Librarian
- Re: RFC 283 (v1) C<tr///> in array context ... Richard Proctor
- Re: RFC 283 (v1) C<tr///> in array cont... Simon Cozens
- Re: RFC 283 (v1) C<tr///> in array ... Bart Lateur
- Re: RFC 283 (v1) C<tr///> in array ... Paris Sinclair
- Re: RFC 283 (v1) C<tr///> in ar... Bennett Todd
- Re: RFC 283 (v1) C<tr///> ... Paris Sinclair
- Re: RFC 283 (v1) C<tr///&... Bennett Todd
- Re: RFC 283 (v1) C<tr... Paris Sinclair
- Re: RFC 283 (v1) C<tr... Bennett Todd
- Re: RFC 283 (v1) C<tr... Paris Sinclair
- Re: RFC 283 (v1) C<tr... Bennett Todd
- Re: RFC 283 (v1) C<tr... Paris Sinclair
- Re: RFC 283 (v1) C<tr... Russ Allbery
