in reply to Counting multiple values in an array...

  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

Replies are listed 'Best First'.
Re^2: Counting multiple values in an array...
by chromatic (Archbishop) on Jun 10, 2010 at 07:46 UTC

    You missed lecture point #0: use lexical filehandles!

      Sorry, I didn't attend that lecture.    :-)