in reply to Sorting with perl
Give the names of the two files as arguments. And if there's a lot of data, you may want to turn the sort into a GRT.#!/usr/bin/perl use 5.8.0; use strict; use warnings 'all'; use sort 'stable'; my ($first, $second) = @ARGV; open my $fh => $first or die "open first: $!\n"; chomp (my @words = <$fh>); close $fh; my $c = 0; my %words = map {$_ => ++ $c} @words; open my $sh => $second or die "open second: $!\n"; my @info; while (<$sh>) { chomp; push @info => [split /\|/]; } close $sh; @info = sort {$words {$a -> [0]} <=> $words {$b -> [0]}} @info; print "@$_\n" for @info; __END__
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Sorting with perl
by fruiture (Curate) on Aug 12, 2002 at 13:14 UTC | |
by Abigail-II (Bishop) on Aug 12, 2002 at 13:56 UTC | |
by fruiture (Curate) on Aug 12, 2002 at 14:35 UTC | |
by Abigail-II (Bishop) on Aug 12, 2002 at 14:51 UTC |