Good day, I like so many, am new Perl. I am trying to search a file for a string, if found, pass it to an array. I don't think what I have done is the best way of doing things, but I learn by getting scripts to work and them improve on it.
I also think I may be missing a few concepts, or at lease the best practice.
When I run the script, I get....
968
968
3026
968
3026
809
968
3026
809
842
968
3026
809
842
25045
968
3026
809
842
25045
57344
I was expecting to get.....
968
3026
809
842
57344
#!C:/Perl/bin/perl.exe
use strict;
use warnings;
### Script Variables
my $FIND = "(C|c)ontent-(L|l)ength:" ;
my $FILES ; # files
my @FILELIST ; # array for files
my $IP_DIR="E:/IP_DIR" ; # Input Directory
my $LINES ;
### Verify Input Directory
opendir(IP_DIR, $IP_DIR) or die ("$IP_DIR does not exist!\n") ;
### Send FILES to array
opendir DIR, $IP_DIR ;
@FILELIST = readdir DIR ;
# Remove the '.' and the '..' from array
delete @FILELIST[0,1] ;
#print "@FILELIST" ;
### Open FILES in FILELIST
foreach $FILES (@FILELIST) {
# chomp $FILES ;
open FILE, "<$IP_DIR\/$FILES";
my @FILE = <FILE> ;
#print @FILE ;
my @START="" ;
for (@FILE) {
if ($_ =~ /$FIND/) {
push(@START,$_) ;
print @START ;
}
}
}