I need to work with .txt files, and filter by name and date stored at the name of the file.
At the moment I achived the following:
my $dir = "t-files\/";
chdir($dir);
foreach $files (glob('*.txt')) {
($sname) = split(/_/, $files);
#($sdate) = "still under work"
print "\nSwitch Name: $sname - Date: still under work";
}
File example names: "s-ar-ar55g-1_20140911-09.txt" | "s-ar-ar55g-1_20141027-09.txt" | etc.
With this script I have the following output:
D:\_perl>test_01.pl
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
Switch Name: s-ar-ar55g-1 - Date: still under work
D:\_perl>
My intention is to extract the date string "20140911" from the file, and stored into a new variable "sdate"
By this way I need to have two variables, so I be able to make comparition with name and date
Is it posible to extract the year, month and day like this "20140911", directly from the name of the txt file?