in reply to Hash Question
I would just do something like this:
Or if you need to store all the data for other purposes:@ACCTS = ("1234", "5678", "6959"); open(IN,"InFile.txt"); %acct=""; while (defined($line = (<IN>))){ foreach $x (@ACCTS) { if ($line =~/$x/){ #only print the first line we see for each account unless( exists $acct{$x} ){ print "$line\n"; $acct{$x}++; } } } }
@ACCTS = ("1234", "5678", "6959"); open(IN,"InFile.txt"); %acct=""; while (defined($line = (<IN>))){ foreach $x (@ACCTS) { if ($line =~/$x/){ push(@{$acct{$x}},$line); } } } foreach $key (sort keys %acct){ print "$key,$acct{$key}[0]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hash Question
by AnomalousMonk (Archbishop) on Jan 10, 2011 at 23:18 UTC | |
|
Re^2: Hash Question
by mmittiga17 (Scribe) on Jan 11, 2011 at 19:33 UTC |