Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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

by HJO (Acolyte)
on Oct 11, 2012 at 09:41 UTC ( #998402=note: print w/ replies, xml ) Need Help??


in reply to Re: 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

Hi McA,

Waow, thanks it worked perfectly, but could you just please explain it to me ^^" I'm unused to your use of : ? %{$values[0][0]} : ();


Comment on Re^2: Error "Can't use an undefined value as a HASH reference" while working with generated objects
Download Code
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

    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; }

      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()

      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^3: Error "Can't use an undefined value as a HASH reference" while working with generated objects
by McA (Deacon) on Oct 12, 2012 at 09:07 UTC

    Hi!

    Sorry for the late reply: Please have a look at http://perldoc.perl.org/perlop.html#Conditional-Operator . This operator is also known as triadic operator. It's a kind of if-then-else-operator.

    Hope it helps

    Best regards
    McA

      Hi,

      Not a problem, I just though you didn't see my reply ^^" Well thanks, it's a little easier to understand now with some documentation.

      Thanks again for your answers

      Regards, HJO

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2014-07-13 19:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (251 votes), past polls