Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Heisenberg Uncertainty Hash

by Roy Johnson (Monsignor)
on Apr 27, 2005 at 04:30 UTC ( #451848=note: print w/replies, xml ) Need Help??

in reply to Heisenberg Uncertainty Hash

Here's a demo of a sub you might find useful. It descends the hash chain checking existence at each level. It returns [a reference to, to ensure logical truth] the value if everything exists.
#!perl use warnings; use strict; sub safe_exists { my ($href, @list_of_descent) = @_; use List::Util 'first'; if (first { not (exists $href->{$_} and $href=$href->{$_}) } @list_of_descent) { return (); } else { return \$href; } } my %hash = ('a' => { 'value' => 1, 'foo' => 'bar', }, 'b' => { 'value' => 2, 'foo' => 'bar', }, 'c' => { 'value' => 3, 'foo' => 'bar', }, ); for (qw(a b c d)) { if (my $href = safe_exists(\%hash, $_, 'value')) { print "$_ value is $$href\n"; } else { print "Key $_ doesn't exist. Valid keys are: "; print join (", ", keys %hash), "\n"; } }

Caution: Contents may have been coded under pressure.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://451848]
[Corion]: marto: No, a Sun Balcony, it was an ill-fated attempt to revive the Sparc series after the Pizzabox :)
[marto]: ah Sun, I sold my Pizzabox in around 2005
[Corion]: I used one at $work as a terminal, but those days are long gone by ;)
[marto]: I have an old IBM infowindow terminal to repurpose, I'll just wire a raspberry piz zero to the cable, providing access and wiFi :P
[marto]: the kids will love it
[Corion]: marto: Hehe ;) I've been toying with the idea of soldering an USB (-C) hub into a keyboard and making it a computer by slotting my phone into that :)

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2018-03-21 11:22 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (267 votes). Check out past polls.