[% setvar title C in array context should return a histogram %]

This file is part of the Perl 6 Archive

Note: these documents may be out of date. Do not use as reference!

To see what is currently happening visit http://www.perl6.org/

TITLE

tr/// in array context should return a histogram

VERSION

  Maintainer: Simon Cozens <simon@brecon.co.uk>
  Date: 24 Sep 2000
  Mailing List: perl6-language@perl.org
  Number: 283
  Version: 1
  Status: Developing

ABSTRACT

tr/// in array context should return a histogram explaining the number of matches for each letter in the pattern.

DESCRIPTION

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 that tr in the array context should return a hash, like this:

    (%foo) = "xyzzy" =~ tr/xyz//

    # %foo is ( x => 1, y => 2, z => 3);

IMPLEMENTATION

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...

REFERENCES

None.