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

Re: Sorting with perl

by fruiture (Curate)
on Aug 12, 2002 at 13:09 UTC ( [id://189473]=note: print w/replies, xml ) Need Help??


in reply to Sorting with perl

Use a Hash!

#!/usr/bin/perl use strict; use warnings; my $guidefile = './guide'; my $flatfile = './flat'; my $delimiter = qr{\s*\|\s*}; my (%guide,@flat); open GUIDE,'<',$guidefile or die "E: open($guidefile): $!"; {my $i = 0; while(<GUIDE>){ chomp; $guide{$_}=$i++ } } close GUIDE; open FLAT,'<',$flatfile or die "E: open($flatfile): $!"; while( <FLAT> ){ chomp; push @flat,[split /$delimiter/]; } close FLAT; foreach( sort { ($guide{ $b->[0] }||0) <=> ($guide{ $a->[0] }||0) } @ +flat ){ print join("\t", exists($guide{$_->[0]}) ? $guide{$_->[0]} : '-', @$_),"\n"; }
--
http://fruiture.de

Log In?
Username:
Password:

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

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

    No recent polls found