Hi monks, not sure if i explained my problem clearly enough, sorry! anyway i'll show you what i've done and it might make it easier to correct me. i am trying to count every number in $array[0] (shown below); all of the same numbers are the same thing (eg all the 1's are the same), i just need to know which occurs the most. i have tried counting every number etc but i cant seem to find which is the most frequent, i just get the number of numbers present returned to me. hope someone can help.
1 1 1 1 2 2 3 4 4 4
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)
e.g 1 4 2 3
n.b
#! /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"; } } }

In reply to Re: wisdom needed by Anonymous Monk
in thread wisdom needed: sorting an array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.