Daniel Gladstone wrote:
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";
 }

Your code doesn't seem to match the problem you stated. What does $cntfldnum contain? If you are searching, as you stated, for a record number then the match pattern should be for column zero: $rec[0] =~ /$pattern/ Could you please clarify your intent?


--

Just my 0.00000002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is available at http://perldoc.perl.org/

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to