You are right that there is unnecessary disk access going on. There are cute/clever ways to do this (
e.g. piping in from
grep), but the easiest way would be swap your print statement with a concatenation:
open my $FH, '<' , $config or die "Cannot open $config: $!\n";
my $data = <$FH>; # Dump the line
$data = '';
while (<$FH>) {
next if /^\s*#|^$/;
$data .= $_;
}
close $FH;
while ($data =~ m/\{([^}]*)\}/gx ) {
print "$1\n";
}
Incidentally, you have a
$data = <$FH>; peppered into your first chunk. Are you meaning to dump the first line of the file? I've included that behavior, but it smells buggy to me.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.