On Apr 19, Lars Henrik Mathiesen said:
>> Date: Thu, 18 Apr 2002 23:44:26 +0200
>> From: Paul Johnson <[EMAIL PROTECTED]>
>>
>> On Thu, Apr 18, 2002 at 07:56:06PM -0000, Lars Henrik Mathiesen wrote:
>> > I would like to write
>> >
>> > for my $key ( $hash{foo}->keys ) { print $hash{bar}->{$key} }
>>
>> This, or something similar was hashed out on p5p, ooooh, about 4 years
>> ago, give or take four years ;-) Actually, I think it might have been
>> when Chip was Pumpking, which would have made it about five years ago.
>
> package hash;
> sub bless { bless shift }
> sub keys { keys %{+shift} }
> sub values { values %{+shift} }
> sub hash { %{+shift} }
>
> package main;
>
> my $href = hash::bless { foo => 1, bar => 2 };
>
> print join ', ', $href->keys;
> print join ', ', $href->values;
> print join ', ', $href->hash;
>
>Tempting --- now if only I could create a method named % or @ ... I'm
>not sure how many optimizations this loses relative to the %{ $href }
>construction, though.
You can; use overload:
package hash;
use overload (
'%{}' => \&hdref,
);
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
<stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
[ I'm looking for programming work. If you like my work, let me know. ]