Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Pathologically Eclectic Rubbish Lister
 
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
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 );

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'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://998408]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (8)
As of 2014-04-18 00:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (460 votes), past polls