[% setvar title C
|Note: these documents may be out of date. Do not use as reference!|
To see what is currently happening visit http://www.perl6.org/
tr/// in array context should return a histogram
Maintainer: Simon Cozens <email@example.com> Date: 24 Sep 2000 Mailing List: firstname.lastname@example.org Number: 283 Version: 1 Status: Developing
tr/// in array context should return a histogram explaining the
number of matches for each letter in the pattern.
This has been on the Perl 5 to-do list for ages and ages. The idea is that when you're transliterating a bunch of things, you want to know how many of each of them matched in your original string.
For instance, while
tr/x// will count the x's,
tr/xy// will count
both x's and y's - you don't know how many of each. So, the proposal is
tr in the array context should return a hash, like this:
(%foo) = "xyzzy" =~ tr/xyz// # %foo is ( x => 1, y => 2, z => 3);
I posted a patch to Perl 5.6 to do this some time back; it's a very simple matter of constructing the hash and incrementing the values every time you do a transliteration of a character. Of course, since we don't know what Perl 6's transliteration operator's going to look like, it's hard to know how to implement an extension to it...