Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: using / accessing nested hash/array references

by state-o-dis-array (Hermit)
on Jan 18, 2011 at 23:30 UTC ( #883014=note: print w/replies, xml ) Need Help??


in reply to using / accessing nested hash/array references

These:
@results = &get_list(); $hostresults[0] = &get_list();
are not equivalent. You have encountered a context issue, the first line above is list context, the second is scalar, in other words, $hostresults[0] is not an array as I think you are expecting. I think what you would want to do is change the second line to something like:
$hostresults[$i] = \@results;
Then $hostresults[0] is a reference to your first data set.

You might want to look at perldsc and perlref

Replies are listed 'Best First'.
Re^2: using / accessing nested hash/array references
by tspfwj (Initiate) on Jan 18, 2011 at 23:40 UTC
    I changed the line to
    $hostresults[0] = \@{&get_list()};
    and I am still receiving the scalar error. I have experimented with initializing like
    my @hostresults = (\@result1,\@result2); #or my @hostresults = (@result1,@result2);
    but I still received errors. My attempts would have been with the same context though. The right side sub returns the array of hash references which is why I left in the line above in my original example. My hope was to show what was happening outside of my context or syntax errors. Thank you
      Sorry, I was kind of hoping that having changed how you are assigning to $hostresults[0] that you might take that as a clue to look at how you are accessing it. Anonyrnous Monk provides a valuable suggestion in referring you to Data::Dumper. Also, have you taken time to check out the links I provided? I think that they will be helpful to you.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://883014]
help
Chatterbox?
[choroba]: As discussed in Using the DATA file handle for ARGV, I usually start my "fun" scripts with *ARGV = *DATA{IO} unless @ARGV;
[choroba]: this was just a remainder
[Discipulus]: ah thanks i forgot that thread (even if i saved it in my homenode)..
[Discipulus]: the node i discovered yesterday nigth was also interesting

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (6)
As of 2016-12-06 08:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (101 votes). Check out past polls.