Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Error: when joining two hashes

by Sami_R (Sexton)
on Feb 19, 2020 at 10:48 UTC ( [id://11113146]=note: print w/replies, xml ) Need Help??


in reply to Re: Error: when joining two hashes
in thread Error: when joining two hashes

Thanks. If its a array ref: when I tried ...

$joined_FS{$_} ||= {( %{$VAR1->{$_}||{}}, @{$VAR2->{@_}||{}} )} for ke +ys(%$VAR1), keys(@$VAR2);

I get same error ... Is it possible to join array ref and hash ref please?

Replies are listed 'Best First'.
Re^3: Error: when joining two hashes
by Fletch (Bishop) on Feb 19, 2020 at 15:35 UTC

    You can't call keys on an array so that's not going to do anything useful. There's a slight whiff of an XY problem in that your data in the two variables isn't of the same shape (HoH vs AoHoH); it might help if you step back a notch and figure out why your previous step(s) aren't making the same outputs.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      You can't call keys on an array so that's not going to do anything useful.

      As of 5.12 (2010), keys @array returns the indicies of the array.

      $ perl -wMstrict -le 'my @x=qw/a b c d/; print for keys @x' 0 1 2 3

      But yeah, in this context it's not useful.

        Derp! I stand corrected there (and should have read my own link first); it's just the difference in shapes and depths of the values means it's not going to do anything useful.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

      Thank you Fletch for the direction.

Re^3: Error: when joining two hashes
by Laurent_R (Canon) on Feb 19, 2020 at 16:31 UTC
    I agree with Fletch that it seems a bit odd that your two variables don't have the same data structure. $VAR1 is a hash ref (or more precisely a reference to a hash of hashes), but $VAR2 is an array ref (a reference to an array of hashes of hashes), but there is no obvious reason in the data that you show to have an array as the top data structure. Is this data structure generated by your program at some earlier point? The proper fix would probably be to correct the part of the program that generates $VAR2, but you don't show that part.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 11:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found