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

Re: Pushing Arrays into Hash without nesting

by BillKSmith (Monsignor)
on Feb 14, 2021 at 20:18 UTC ( #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}} ;

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2022-05-25 17:05 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (90 votes). Check out past polls.