in reply to wisdom needed: sorting an array
i want the number which occurs the most to be ranked at the top of the output (only one of each number needs to be ranked)1 1 1 1 2 2 3 4 4 4
n.be.g 1 4 2 3
#! /usr/local/bin/perl -w use strict; my $num_of_params; $num_of_params = @ARGV; if ($num_of_params < 2) { die ("\n You haven't entered enough parameters !! \n\n"); } open (FILE, $ARGV[0]) or die "unable to open file"; open (OUTFILE, ">$ARGV[1]"); my $line; my @array; my $number; my $count=0; while (<FILE>) { $line = $_; chomp ($line); @array = (); @array = split (/\s+/, $line); foreach $number ($array[0]) { ++$count; print "$count\n"; print OUTFILE "$count\n"; if ($number != $number-1 ) { print "$number\n"; print OUTFILE "$number\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: wisdom needed
by Juerd (Abbot) on Jun 06, 2002 at 10:43 UTC | |
|
Re: Re: wisdom needed
by marvell (Pilgrim) on Jun 06, 2002 at 10:50 UTC | |
by Anonymous Monk on Jun 06, 2002 at 14:15 UTC |