in reply to skip junk lines in csv before header
Alternate solution. Let perl do the work for you.
#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11145686 use warnings; open my $fh, '<', \<<END or die; # FIXME for testing first junk line then a blank line another junk line fieldname1,fieldname2 value1,value2 more,body and,still more,body END do { local $/ = "fieldname"; <$fh> }; # read through "fieldname" my $header_line = "fieldname" . <$fh>; # complete the line print "header: $header_line"; while( <$fh> ) # FIXME for testing { print " body: $_"; }
Outputs:
header: fieldname1,fieldname2 body: value1,value2 body: more,body body: and,still body: more,body
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: skip junk lines in csv before header
by GotToBTru (Prior) on Jul 28, 2022 at 12:19 UTC | |
by AnomalousMonk (Archbishop) on Jul 28, 2022 at 12:53 UTC | |
by LanX (Saint) on Jul 28, 2022 at 13:16 UTC | |
by AnomalousMonk (Archbishop) on Jul 28, 2022 at 15:28 UTC | |
by LanX (Saint) on Jul 28, 2022 at 15:45 UTC |