in reply to Re^2: Perl Script performance issue
in thread Perl Script performance issue

Hello again Tara,

You have the line:

$final_data = ` grep "$key_pattern" "${indir}/${lkp_file_name}" |cut - +d"|" -f"$data_location"`;

Here is one way to write this in pure Perl (untested):

my $file = $indir . '/' . $lkp_file_name; open(my $fh, '<', $file) or die "Cannot open file '$file' for reading: $!"; my @matched_lines = grep { /\Q$key_pattern/ } <$fh>; close $fh or die "Cannot close file '$file': $!"; my @fields; for my $line (@matched_lines) { my $field = (split /\|/, $line)[$data_location - 1]; chomp $field; push @fields, $field; } $final_data = join "\n", @fields;

(There should also be some error handling to deal with the possibility that a matched line contains an insufficient number of fields.)

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,