Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Pushing Arrays into Hash without nesting

by BillKSmith (Monsignor)
on Feb 14, 2021 at 20:18 UTC ( [id://11128372]=note: print w/replies, xml ) Need Help??


in reply to Pushing Arrays into Hash without nesting

You do have a problem with 'list', but not in the way that you think. The first sentence of the DESCRIPTION section of the documentation for Data::Dumper is:
Given a list of scalars or reference variables, writes out their contents in perl syntax.

In your first call to Dumper, you specified '%hash', clearly a hash, not a scalar or a reference variable. In list context, perl converts this to a list of alternating keys and values. In your case, there is only one of each. They are dumped as '$VAR1' and '$VAR2'. By convention, you should specify a reference to your hash Dumper \%hash. There is a similar problem with all your other dumps. Correctly formed dumps would have helped you spot the problem ($source{$data} in addSomeNumbersFromSource contains a reference to an array, not an array). A simple fix is to dereference it before assigning to '@array'.

#my @array = $source{$data} ; my @array = @{$source{$data}} ;
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-25 12:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found