Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Will the range operator help you?

by Rhose (Priest)
on Sep 19, 2001 at 17:15 UTC ( #113321=note: print w/replies, xml ) Need Help??

in reply to How to remove lines out of an ascii file

How about this? The range operator will allow you to skip (not remove) lines up to (and including) the matching line.
use strict; while (<DATA>) { next if 1../^CPN/; #-- Parse lines... print; } __DATA__ BOM Report ------------------- BOM : Date : 19 Sep 2001 14:57:17 Total # of CPN's (41) ----------------------- CPN Quantity MPN Vendor 51-0597-000 15 06035C103MAT2A AVX 51-0597-000 15 06035C103MAT4A AVX 51-0597-000 15 C0603C103M5RAC KEMET ELECTRONICS

Replies are listed 'Best First'.
Re: Will the range operator help you?
by broquaint (Abbot) on Sep 19, 2001 at 18:13 UTC
    The operator you speak of is not the range operator, but is in fact the flip-flop operator (oooh, it's a sneaky one!). I believe this was grabbed from AWK, and is *uber* handy when doing text processing (like AWK). You can have all sorts of funky variations on the above, from fancy regexps to simple line numbers. I shall use the example from the always informative perl docs (man perlop) -
    if (101 .. 200) { print; } # print 2nd hundred lines next line if (1 .. /^$/); # skip header lines s/^/> / if (/^$/ .. eof()); # quote body # parse mail messages while (<>) { $in_header = 1 .. /^$/; $in_body = /^$/ .. eof(); # do something based on those } continue { close ARGV if eof; # reset $. each file }
    Indeed a thing of beauty!


Re: Will the range operator help you?
by juo (Curate) on Sep 19, 2001 at 18:57 UTC

    This works fine but I don't want to include my matching line into the skip. Is this possible.

      Sure if you just do something like this -
      while(<FILE>) { next unless /^CPN/ .. eof() and !/^CPN/; [munge data here] }


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2019-08-20 10:25 GMT
Find Nodes?
    Voting Booth?

    No recent polls found