Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: sorting a table columns using hashes

by Utilitarian (Vicar)
on May 05, 2011 at 15:39 UTC ( [id://903169]=note: print w/replies, xml ) Need Help??


in reply to sorting a table columns using hashes

Does lowest value in column 5 override highest value in column 7 or versa vice?
ie with the data
xhahhxha 60 3 hahaghagah 7 1 101 xhahhxha 60 3 jrthtahtat 8 1 110 xhahhxha 60 3 shdgehsh 10 1 150
What do you output?

print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Replies are listed 'Best First'.
Re^2: sorting a table columns using hashes
by ihperlbeg (Novice) on May 05, 2011 at 15:46 UTC
    with this data: xhahhxha 60 3 hahaghagah 7 1 101 xhahhxha 60 3 jrthtahtat 8 1 110 xhahhxha 60 3 shdgehsh 10 1 150 Output will be: xhahhxha 60 3 hahaghagah 7 1 101
      #!/usr/bin/perl while (<DATA>){ chomp; @record=split(/\s+/,$_); if (defined $records{$record[0]}){ # We've seen it before and need + to compare the data if($record[1] < $records{$record[0]}->[1]){ # we have a smalle +r value and so should use this $records{$record[0]}->[1] = $record[1]; } if ( ($record[4] < $records{$record[0]}->[4]) ){ $records{$record[0]}->[3] = $record[3]; $records{$record[0]}->[4] = $record[4]; $records{$record[0]}->[6] = $record[6]; }elsif ( ( $record[4] == $records{$record[0]}->[4]) && ($recor +d[6] > $records{$record[0]}->[6]) ){ $records{$record[0]}->[3] = $record[3]; $records{$record[0]}->[6] = $record[6]; } } else{ @{$records{$record[0]}}=@record; } } for $key (reverse sort keys %records){ print join ("\t", @{$records{$key}}),"\n"; } __DATA__ xhahhxha 60 3 hahaghagah 10 1 101 xhahhxha 60 3 jrthtahtat 8 1 110 xhahhxha 60 3 shdgehsh 8 1 150 hsghtahs 100 19 hahaghagah 10 20 200 hsghtahs 100 19 jrthtahtat 10 20 300 hsghtahs 100 19 shdgehsh 10 20 400 __END__ xhahhxha 60 3 shdgehsh 8 1 150 hsghtahs 100 19 shdgehsh 10 20 400
      Ugly but functional

      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (3)
As of 2024-04-25 19:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found