C
ccc31807
The input is a flat file (pipe separated) with thousands of records
and tens of columns, similar to this. The first column is a unique
key.
42546|First|Middle|Last|Street|City|State|Zip|Country|Attr1|Attr2|
Attr3 ...
The input is processed and the output consists of multi-page PDF
documents that combine the input file with other files. The other
files reference the unique key. I build a hash with the input files,
like this:
my %records;
while(<IN>)
{
my ($key, $first, $middle, $last ...) = split /\|/;
$record{$key} = {
first => $first,
middle => $middle,
last => $last,
...
}
Running this script results in thousands of PDF files. The client has
a need for individual documents, so I modified the script to accept a
unique key as a command line argument, which still reads the input
document until it matches the key, creates one hash element for the
key, and exits, like this:
#in the while loop
if ($key == $command_line_argument) {
#create hash element as above
last;
}
The client now has a need to create a small number of documents. I
capture the unique keys in @ARGV, but I don't know the best way to
select just those records. I can pre-create the hash like this:
foreach my $key (@ARVG)
(
$records{$key};
}
and in the while loop, doing this:
if(exists $records{$key})
{
#create hash element as above
}
but this still reads through the entire input file.
Is there a better way?
Thanks, CC.
and tens of columns, similar to this. The first column is a unique
key.
42546|First|Middle|Last|Street|City|State|Zip|Country|Attr1|Attr2|
Attr3 ...
The input is processed and the output consists of multi-page PDF
documents that combine the input file with other files. The other
files reference the unique key. I build a hash with the input files,
like this:
my %records;
while(<IN>)
{
my ($key, $first, $middle, $last ...) = split /\|/;
$record{$key} = {
first => $first,
middle => $middle,
last => $last,
...
}
Running this script results in thousands of PDF files. The client has
a need for individual documents, so I modified the script to accept a
unique key as a command line argument, which still reads the input
document until it matches the key, creates one hash element for the
key, and exits, like this:
#in the while loop
if ($key == $command_line_argument) {
#create hash element as above
last;
}
The client now has a need to create a small number of documents. I
capture the unique keys in @ARGV, but I don't know the best way to
select just those records. I can pre-create the hash like this:
foreach my $key (@ARVG)
(
$records{$key};
}
and in the while loop, doing this:
if(exists $records{$key})
{
#create hash element as above
}
but this still reads through the entire input file.
Is there a better way?
Thanks, CC.