Hello all,
I was curious if this is possible in Perl 6:
%hash{ 'foo' & 'bar' } = 'some value';
# %hash{'foo'} eq 'some value' and %hash{'bar'} eq 'some value'
or perhaps
%hash{ 'foo' | 'bar' } = 'some value';
In other words, is it possible to assign the same value to multiple hash
keys simultaneously using junctions (or some other new mechanism)? In
Perl 5, I would do
$hash{'foo'} = $hash{'bar'} = 'some value';
which gets tedious with more than one hash key. 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. 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. Reading the synopses, one possibility seems
to be
%hash<foo bar> >>= 'some value';
using hyper operators, but is that really the best way?
Regards,
Ville Koskinen