A better approach would be:
open DATFILE, "$path/$whatdir.txt" or die "Could not open file: $!";
while (<DATFILE>) {
chomp;
if (/^\Q$goto\E$/) {
$line = $_;
last;
}
next;
}
That is less memory intensive.
Code:
my $line; open DATFILE, "$path/$whatdir.txt" or die "Could not open file: $!";
while (<DATFILE>) {
chomp;
if (/^\Q$goto\E$/) {
$line = $_;
last;
}
next;
}
That is less memory intensive.