I have a file that looks like this
*TRANSACTION STARTED*
[020t CARD INSERTED
[020tCARD: *************5845
DATE 01-02-16 TIME 05:45:52
05:46:26 GENAC 1 :
@Iord-Ivan Try to study
what is the datatype.?
File handling
What is handler.
Your $somefile
store only the file name. Then you iterate the while loop using $somefile
. But your $somefile
contain only the file name not contain the file content.
You file content is stored into the $fh
handler so iterate the while loop for $fh handler. Then check it line by line.
use warnings;
use strict;
my $somefile = "input.txt";
open (my $fh, '<:encoding(UTF-8)', $somefile) or die "Could not open file '$somefile' $!";
print "$somefile open";
while (<$fh>) {
if (/TRANSACTION STARTED/ .. /TRANSACTION END/)
{
next if /TRANSACTION\s*(STARTED|END)/;
print $_;
}
}
After studying perl, finish the balance program(FILE WRITE). :)