On Mon, Jun 08, 2009 at 12:02:43PM +0100, Ville Koskinen wrote:
: An alternative is always
: @hash{qw(foo bar)} = ('some value') x 2;
: which is probably
: %hash<foo bar> = ('some value') x 2;
: in Perl 6, but you always need to take care to write the correct integer
: in the list replication.

Two problems.  First, list replicaiton is xx rather than x, and second,
you *don't* have to write the integer, because you can use the
"Whatever" star:

    %hash<foo bar> = 'some value' xx *;

That makes an arbitrarily long list of strings.

: The best way is, of course, (in Perl 5)
: {
:    my @keys = qw(foo bar);
:    @ha...@keys} = ('some value') x @keys;
: }
: but then you need the @keys array, which needs to be defined if you are
: dealing with literal values.

Perl 6's new * term is useful in many such places where you just want
to say, "I dunno, you figure it out."

: Reading the synopses, one possibility seems to be 
: %hash<foo bar> >>= 'some value';
: using hyper operators, but is that really the best way?

If you'll define "best way", I'll tell you if it is.  :)

The relative efficiency is going to be difficult to predict because
any of these could be poorly implemented and do too much busywork.
Apart from that, it's gonna come down primarily to what you think
is readable.

By the way, infix hypers want to go on both sides, like this:

    %hash<foo bar> »=» 'some value';


Reply via email to