1. You should indent your code properly so that it is easier to read.
  2. You don't need to read the whole file into an array in order to accomplish your task.
  3. You don't have to put my in front of every variable name in a list, you just need to put it in front of the left parenthesis for the entire list.
  4. You are only using one field ($caseNumber) from each record so there is no need to create variables for the other fields that you are not using.
  5. You are defining a subroutine but you never call the subroutine so the code inside it never runs.

You may want something like this (UNTESTED):

#!/usr/bin/perl use warnings; use strict; # open file my $file = shift @ARGV; open FILE1, '<', $file or die "Can't open '$file': $!"; my %caseCount; # Use a while loop to read through the data while ( <FILE1> ) { my $caseNumber = ( split /\t/ )[ 1 ]; $caseCount{ $caseNumber }++; } # close the file you don't need it any more close FILE1; #do something here with values in %caseCount

In reply to Re: Counting multiple values in an array... by jwkrahn
in thread Counting multiple values in an array... by dukea2006

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.