Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

lines that I do not wish to be skipped

by steph_bow (Pilgrim)
on Mar 11, 2008 at 15:48 UTC ( [id://673533]=perlquestion: print w/replies, xml ) Need Help??

steph_bow has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks

I want to skip lines that begin with PA,PB or PC except PATY, but i do not know how to do this

Here is my command to skip the line.

next if (/^(PA|PB|PC).*/); # but I want to keep PATY

Replies are listed 'Best First'.
Re: lines that I do not wish to be skipped
by olus (Curate) on Mar 11, 2008 at 16:01 UTC
    while (<DATA>) { next if (/^(PA(?!TY)|PB|PC).*/); print $_; } __DATA__ PAfr PBhghg PAY fvfv PT PATE PATY hfkd dfffPATY
Re: lines that I do not wish to be skipped
by Fletch (Bishop) on Mar 11, 2008 at 15:51 UTC

    Look for "negative lookahead" in perlre, or break it into two separate conditions (if it starts with /P[ABC]/ and it doesn't start with /PATY/ then skip to the next line).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

Re: lines that I do not wish to be skipped
by Narveson (Chaplain) on Mar 11, 2008 at 16:12 UTC
Re: lines that I do not wish to be skipped
by halfcountplus (Hermit) on Mar 11, 2008 at 19:16 UTC
Re: lines that I do not wish to be skipped
by romandas (Pilgrim) on Mar 11, 2008 at 17:26 UTC
    Completely untested, but would this work?

    next if (/^(PA|PB|PC).*/) unless (/^PATY/);

    Edit: Sorry; this was just meant as speculation. Probably better suited for the CB; my mistake.
      It would not.

      You cannot hang two statement modifiers on the same statement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://673533]
Approved by olus
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found