I have a large file (several million records), with some records having duplicate ID numbers ($idnum).
I want to extract just the unique records, however as the records are very large I can't, for memory reasons, use the $record, in the below script, as a value to the hash.
I have therefore tried using a reference (see below) however this does not dereference as it would do with a normal scalar.
I've not used a reference as a value before and would appreciate any help (if there's a better way please feel free to suggest too.)
Many Thanks
open (INFILE, "<c:\\file1.dat" or die;
%seen = ();
while ($record = <INFILE>) {
$idnum = substr($record, 8, 8); #position of the unique id
$ref = \$record;
$seen{$idnum} = $ref;
}
foreach $var (values %seen) {
print $$var."\n";
}
I want to extract just the unique records, however as the records are very large I can't, for memory reasons, use the $record, in the below script, as a value to the hash.
I have therefore tried using a reference (see below) however this does not dereference as it would do with a normal scalar.
I've not used a reference as a value before and would appreciate any help (if there's a better way please feel free to suggest too.)
Many Thanks
open (INFILE, "<c:\\file1.dat" or die;
%seen = ();
while ($record = <INFILE>) {
$idnum = substr($record, 8, 8); #position of the unique id
$ref = \$record;
$seen{$idnum} = $ref;
}
foreach $var (values %seen) {
print $$var."\n";
}