I have an array filled with 4 digit numbers (@nums) that correspond
to conf files which use the numbers as the file name, like so: 0000.conf
I am reading a file foreach element in the array and checking
the file for a pattern like this :
use strict;
use warnings;
foreach my $num (@nums) {
open my $fh, "<", "$num.conf"
or warn "cannot open $num.conf : $!";
while(<$fh>) {
if (/^SomePattern=(.+)/) {
print "$num : $1\n";
}
}
}
I am extracting the part of the pattern I want using () and the
special var $1.
This seems to be working except it only prints the results of the last file that is opened, instead of printing the results each time the foreach loop passes and opens a file, which is what I expected.
I am still learning Perl, so any detailed explanations of what I missing here will be greatly appreciated.
Global symbol "$num" requires explicit package name at..How do.conffiles look like?myand I do have the closing bracket for the while loop both in my original code and I added them here. The .conf files area few hundred lines each. I know that "/^SomePattern=(.+)/" is in each file.@numscomes to be. Your code does not, and@numsis a magical value that comes from nowhere, and as such, your code is not "complete".