do { local $/ = "fieldname"; <$fh> }; # read through "fieldname"
The local $/ = "fieldname"; statement sets the $/ input record separator special variable (see perlvar) to the literal 'fieldname' string.
This sets "paragraph" read mode: (no: see Update below)
| This causes <$fh> to
read the input stream from the beginning of the file (in this particular case) until the end of the first point at which the 'fieldname' string is encountered. Since the field names are apparently unambiguously known, this reads (almost) all the way through the first field name. The $/ variable is assigned local-ly in a do-block, so it returns to its previous value (the "\n" default in this case) at the end of the block.
my $header_line = "fieldname" . <$fh>; # complete the line
Since we (apparently) know the header line begins with 'fieldname', assign $header_line this initial value and complete reading the line with another <$fh>. This reads through the end of the line because $/ has restored to its original newline value.
Update:
This sets "paragraph" read mode: ...No, this is not "paragraph" (sometimes called "paragrep") read mode, it is normal read mode. See $/ in perlvar for a discussion of paragraph mode.
In normal read mode, a file is read until just after the sequence of one or more characters in the $/ special variable is encountered (and including that sequence), or until the end of file if the $/ sequence is never encountered. Usually, $/ is a single "\n" (newline) character, but it can be any non-empty string. Whatever non-zero-length sequence of characters it may be, this is normal read mode.
Give a man a fish: <%-{-{-{-<
In reply to Re^3: skip junk lines in csv before header (updated)
by AnomalousMonk
in thread skip junk lines in csv before header
by karlberry
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |