Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^3: Error "Can't use an undefined value as a HASH reference" while working with generated objects

by Anonymous Monk
on Oct 11, 2012 at 10:04 UTC ( #998408=note: print w/replies, xml ) Need Help??


in reply to Re^2: Error "Can't use an undefined value as a HASH reference" while working with generated objects
in thread Error "Can't use an undefined value as a HASH reference" while working with generated objects

my %valeur; if( @values and defined $values[0] and 'ARRAY' eq ref $values[0] and defined $values[0][0] and 'HASH' eq ref $values[0][0] ) { %valeur = %{ $values[0][0] }; }

my %valeur; if ( my $want = Dive( \@values, qw/ 0 0 / ){ %valeur = %$want; }
  • Comment on Re^3: Error "Can't use an undefined value as a HASH reference" while working with generated objects
  • Select or Download Code

Replies are listed 'Best First'.
Re^4: Error "Can't use an undefined value as a HASH reference" while working with generated objects
by tobyink (Abbot) on Oct 11, 2012 at 14:03 UTC

    The Data::Diver example will die if $values[0][0] is defined and true but not a hashref - e.g. if it's an arrayref.

    use Data::Diver 'Dive'; use Scalar::Does 'does'; if (my $want = Dive( \@values, qw/ 0 0 / )) { %valeur = %$want if does($want, 'HASH'); }
    perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re^4: Error "Can't use an undefined value as a HASH reference" while working with generated objects
by HJO (Acolyte) on Oct 11, 2012 at 10:28 UTC

    Waow thanks, I really didn't push the defined so far ...

    I just tested it (the first method, I'm having some trouble with your second, some undeclared varibles...), It's working as well, thanks

      the first method, I'm having some trouble with your second, some undeclared varibles...

      Its a missing ")"

      one pair for if() and another for Dive()

        Hi,

        Well yes it was, I also didn't used the proper way of calling the module, I check in the doc and found out, it seems to be working also just fine, thanks a lot

        PS : I was suppose to call it that way : use Data::Diver qw( Dive );

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998408]
help
Chatterbox?
[Discipulus]: well i'm still at the end of the food chain..
[Discipulus]: so a new life as krill in prague will be good
[erix]: wtf -- what's the idea, is this trolling, advertising, or what?
[Discipulus]: but realisticly choroba your company would a hire a programmer as me?
Discipulus spent ~3 hours on the roof.. with mediocre results..
[Eily]: what were you trying to do on the roof Discipulus?
[Eily]: if I had done the same here, I'd contain a swimming-pool worth of water by now...
[Discipulus]: i put some shodowing cloth against the killer sun. but i'm still not happy with this

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-06-29 12:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (663 votes). Check out past polls.