Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: Referencing/returning array of hashes from sub

by chromatic (Archbishop)
on Jun 08, 2011 at 18:36 UTC ( [id://908761]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Referencing/returning array of hashes from sub
in thread Referencing/returning array of hashes from sub

Dereference your references as you need to work with them. There's no syntactic need to expand them into non-references. Instead of:

my @expanded = @$reference; for my $element (@expanded) { ... }

... you can just as well write:

for my $element (@$reference) { ... }

Replies are listed 'Best First'.
Re^4: Referencing/returning array of hashes from sub
by PoGGiE (Initiate) on Jun 08, 2011 at 20:26 UTC
    Thanks, I've managed to fix my problem now (at last!). Thanks for the help.

    Scrapping the big
    my (@date, ...) = (@$date_ref)

    and replacing with
    my @date = @$date_ref; my @F_SCORE = @$F_SCORE_ref; my @F_SCORE_BOX = @$F_SCORE_BOX_ref; my @F_ROA = @$F_ROA_ref; my @F_CFO= @$F_CFO_ref; my @F_dROA = @$F_dROA; my @F_ACCRUAL = @$F_ACCRUAL_ref; my @F_dLEVER = @$F_dLEVER_ref; my @F_dLIQUID = @$F_dLIQUID_ref; my @F_EQOFFER = @$F_EQOFFER_ref; my @F_dTURN = @$F_dTURN_ref; my @F_dMARGIN = @$F_dMARGIN_ref;

    did the trick (although I'm not sure why).
      although I'm not sure why

      Array assignments are greedy, just as other people have said. How is Perl to know that in:

      my (@date, @F_SCORE, ...) = (@$date_ref, @$F_SCORE_ref, ...);

      ... @date should only slurp up the elements from the flattening of @$date_ref into a list? By the time the assignment occurs, Perl has forgotten how many elements $date_ref contained.

      By the way, as I wrote before, there's no obvious and particular need to perform this copying operation. It's probably just busy work. If you're having trouble figuring out how to work with references in place, ask away and we'll help you figure out how to avoid it.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-25 14:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found