Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Cleaner build of an AoH for nested loop?

by bradcathey (Prior)
on Mar 06, 2009 at 13:53 UTC ( [id://748858]=note: print w/replies, xml ) Need Help??


in reply to Re: Cleaner build of an AoH for nested loop?
in thread Cleaner build of an AoH for nested loop?

This was the eloquence I was looking for kyle, though the -1 list counters looked odd at first. But my original counters and looping just didn't feel "best practices."

Thanks.

—Brad
"The important work of moving the world forward does not wait to be done by perfect men." George Eliot
  • Comment on Re^2: Cleaner build of an AoH for nested loop?

Replies are listed 'Best First'.
Re^3: Cleaner build of an AoH for nested loop?
by kyle (Abbot) on Mar 06, 2009 at 17:44 UTC

    If the -1 index bothers you, you can build the list backwards. In the else clause, unshift instead of push, then you can use refer to the front of the list with [0] instead of the end with [-1]. Then when it's done, use reverse to get the original order. Given that, you have to decide if you want to have to take the extra step to reverse the list, or live with the odd look of [-1].

    foreach my $case ( @{$all_cases} ) { if ( $case_list && $case->{examiner} eq $case_list->[0]->{examiner} ) { push @{ $case_list->[0]->{casedata} }, $case; } else { unshift @{$case_list}, { examiner => $case->{examiner}, casedata => [$case] }; } } @{$case_list} = reverse @{$case_list};

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-24 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found