Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Pushing Arrays into Hash without nesting

by BillKSmith (Prior)
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}} ;
Bill

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2021-04-15 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?