I thought this would be easy but I can not get it to work - can someone
please help me:
Problem: I have a file of 7.5 million records that are pipe delimted, the
first field is a record
number. I want to search for around 10 records with a specific record number
and if they
meet that condition, output them to a secondary output. And if it does not
meet the record
number criteria, output to the primary output.
Code so far(Please don't laugh - I am a newbie)
#!/usr/bin/perl -w
use strict;
# pullbad filename fieldtocount
die "usage: count <filename> <count fldnum> \n" unless (@ARGV == 2);
my ($filename, $cntfldnum) = @ARGV;
$cntfldnum--; # zero-base fldnum
my $records = 0; # count records processed
open(IN, $filename) or die "could not open $filename $!\n";
my %count = (); # hash the count key and value here
while (<IN>) {
$records++;
my @rec=split(/\|/,$_);
#$count{$rec[$cntfldnum]}++;
if ($rec[$cntfldnum] =~ m/\D/g) {
print STDERR $rec[$cntfldnum] . " -> " . $rec[0] . " record # = " .
$records . "\n";
}
Daniel Gladstone
Email: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>