Matthijs van Duin writes:
> On Tue, Apr 20, 2004 at 10:55:51AM -0700, Larry Wall wrote:
> >The flip side is that, since we won't use C<`> as an operator in Perl
> >6, you're free to use it to introduce any user-defined operators
> >you like, including a bare C<`>. All is fair if you predeclare.
> >Most languages won't even give you that...
>
> I just realized there's another operator that has no infix meaning yet, and
> so is free to use (and perhaps more visually pleasing):
>
> %hash\key (or $foo\bar\baz\42 )
>
> vaguely reminiscent of DOS/Win32 paths :-D
>
> Just curious, when adding such an operator myself, would it be possible to
> make it work on both hashes and arrays, without making the op very slow?
macro infix:\ ($cont, $key)
is parsed(/$?key := (-?<letter>\w* | \d+)/)
{
if $key ~~ /^\d+$/ {
"($cont).[$key]";
}
else {
"($cont).Â$keyÂ";
}
}
That does all the magic at compile time.
Luke