in reply to Re: Re: Re: Extracting Header
in thread Extracting Header
I think you meant -ni.bak, not -pi.bak, there. As it stands you'll print out every line in the file once, and the interesting ones twice, which is suboptimal. :-)
As an alternative solution, if you know the number of lines in your header ahead of time, you can skip that number of lines using the flip-flop operator (..), thus:
#!/usr/bin/perl -w # I'll assume for the sake of variety that we want to process the info +rmation # in the file, not just delete the fluff my $header_lines = 3; while (<>) { next if 1 .. $header_lines; chomp; my @data = split; &munge(@data); }
Note that I used split to divide the line up, but if the data fields are fixed-width and could contain embedded spaces, you'd be better off using unpack to split the line up (if they're variable-width and could contain embedded spaces, I recommend a different data format).
|
|---|