I was wondering if someone could help me better understand what this given code to parse a text file is doing.
while ($line = <STDIN>) {
@flds = split("\t", $line);
foreach $fld (@flds) {
if ($fld =~ s/^"(.*)"$/\1/) {
$fld =~ s/""/"/g;
}
}
print join("\t", @flds), "\n";
}
We are given this block of code as a start to parse a text file such as.
Name Problem #1 Comments for P1 E.C. Problem Comments Email
Park, John 17 Really bad. 5 [email protected]
Doe, Jane 100 Well done! 0 Why didn't you do this? [email protected]
Smith, Bob 0 0 [email protected]
...which will be used to set up a formatted output based on the parsed text.
I'm having trouble fully understanding how the block of code is parsing and holding the information so that I can know how to access certain parts of the information I want. Could someone better explain what the above code is doing at each step?