I wrote a Perl program that reads text from a text file and prints it.
I want to print a string with a specific format.
For example, there are lines like this:
information:
Ahmad.prn:592118:2001:7:5:/Essay
Ashford.rtf:903615:2001:6:28:/usr/Essay
Barger.doc:243200:2001:7:4:/home/dir
end of Information.
I want to read only these three lines:
Ahmad.prn:592118:2001:7:5:/Essay
Ashford.rtf:903615:2001:6:28:/usr/Essay
Barger.doc:243200:2001:7:4:/home/dir
I think the meaning of the fields is:
Ahmad.prn <- file name
592118 <- size of file
2001:7:5 <- created date
/Essay <- path of file
My code is:
use strict;
use warnings;
open (my $infh, "<", $file)||die "cant open";
while(my $line = <$infh>) {
chomp ($line);
if ($line =~ /(what regular expression do I have to put in here?)/) {
print "$line";
}
}
close ($infh);
source
share