Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re: Re: Re: Re: Extracting Header

by ChemBoy (Priest)
on Aug 07, 2002 at 04:02 UTC ( #188228=note: print w/ replies, xml ) Need Help??

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).

If God had meant us to fly, he would *never* have given us the railroads.
    --Michael Flanders

Comment on Re: Re: Re: Re: Extracting Header
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://188228]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2015-12-02 01:45 GMT
Find Nodes?
    Voting Booth?

    My keyboard shows this many letters:

    Results (31 votes), past polls