develooper Front page | perl.perl6.language | Postings from May 2004

idiom for filling a counting hash

Thread Next
From:
=?iso-8859-1?Q?St=E9phane?= Payrard
Date:
May 18, 2004 14:14
Subject:
idiom for filling a counting hash
Message ID:
20040518211430.GD27986@stefp.dyndns.org
I use over and over this idiom in perl5:

   $a{$_}++ for @a;

This is nice and perlish but it gets easily pretty boring
when dealing with many list/arrays and counting hashes.

I thought overloading the += operator

   %a += @a;

Probably that operator should be smart enough to be fed with
a mixed list of array and hashes as well:

  %a += ( @a, %h);  #  would mean %a += ( @a, keys %h)

I am not to sure how one can use hyperators, well I meant the
hyped hyperoperators, to juggle with lists and counting hashes.
One may want to feed multiple arrays to a single hash or one
array to multiple hashes. To add some salt to the problem
"Multiple" can translate to an "array of" :

   my @ary_of_h of Hash; @ary_of_h += @a;

Having real types in Perl6 will allow to slice, dice, splice data
in many nice ways. Damian can even spice that with junctions.
Fear. Fear.



--
  stef

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About