[EMAIL PROTECTED] (Juerd) writes:

> Angel Faus skribis 2004-04-19 22:43 (+0200):
>> If we really need a ultra-huffman encoding for hash subscriptors, I 
>> have always dreamt of being able to do:
>>   %hash/key
>>   $hashref/foo/bar/baz/quux
>>   ...
>
> I'd hate to give up dividing slash. It's one of the few operators that I
> sometimes type without whitespace. Simple because 1/10 is good enough
> and 1 / 10 is very wide.

You can have both, though.

>>    for /home/angel -> $file {
>
> That would mean giving up // for regexes (i.e. making the m
> mandatory).

Since modifiers have to be up front, and since hash slices won't have
a trailing '/', I don't think there's any ambiguity -- anything ending
in a '/' is a regex, anything otherwise is a hash slice.

/s

package DH;
require Tie::Hash;

@ISA = 'Tie::StdHash';

sub TIEHASH {
    return bless {}, 'DH';
}

sub SCALAR {
    return shift;
}

sub STORE {
    my ($h, $k, $v) = @_;
    $h->{$k} = $v;
}

use overload '/' => sub {
    my ($x, $y, $rev) = @_;
    if (!$rev) {
        if (ref $y eq 'ARRAY') {
            return [EMAIL PROTECTED]@$y}];
        } else {
            return $x->{$y};
        }
    } else {
        return $y / keys %$x;
    }
};

package main;

my %h;
tie %h, 'DH';
%h = qw(a 1 b 2 c 3);

my $xs = %h / [qw(a c)];
print %h / 'a', "\n";
print "@$xs\n";

Reply via email to