dLux <[EMAIL PROTECTED]> writes:
> Hello!
>
> I want to make do a nested hash structure, which seems like that:
>
> my $pname = $self->{db}->{product}->offers->{ $product_id} ->
> {name};
>
> This kind of structures can be easily created by TableMap.
>
> Problem: If any of the hash keys are undef, then perl "die"-ing with
> an error: Cannot use undef as a HASH reference...
>
> I suggest two kind of solution in the new (perl6) language, because
> I think perl5 don't have good solution for that:
>
> 1, $__ variable, which is the result of the last operation, e.g:
>
> my $pname = $self->{db} && $__->{product} && $__->offers && $__->{
> $product_id } && $__->{name}
>
> 2, &&$ operator, which can be used like that:
>
> my $pname = $self->{db &&$ ->{product} &&$ ->offers &&$ -> {
> $product_id } &&$ ->{name};
>
> I suggest the second, because it is more straightforward, but the
> first is more flexible.
reduce {last unless defined $a; eval "\$a->$b"} $self,
qw/{db} {product} offers {$product_id} {name}/;
Hmm... that is a tad unwieldy. And we don't have reduce yet. And I'm
not entirely sure that last would work how you want it to...
--
Piers