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

Re: Building a hash from file and getting wrong result.

by kcott (Archbishop)
on May 15, 2017 at 20:41 UTC ( [id://1190347]=note: print w/replies, xml ) Need Help??


in reply to Building a hash from file and getting wrong result.

G'day Ed,

I didn't spend a huge amount of time going through your code; however, this part stood out as a potential problem:

foreach my $recid ( reverse sort %SeqOrders ) ...

That will expand all keys and values in the hash to form a list; that list will then be sorted and then reversed. Consider this minimal example of what's happening:

$ perl -MData::Dump -e '%x = qw{a 1 b 2 c 3}; dd \%x; dd { reverse sor +t %x }' { a => 1, b => 2, c => 3 } { 2 => 1, a => 3, c => "b" }

The foreach loop will set all keys and values to $recid; that will be twice the number of the keys and hence "an output file twice the size of the expected result".

You probably want something closer to:

my %rev_seq = reverse %SeqOrders; for my $recid (sort keys %rev_seq) { ... }

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-19 16:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found