Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: Print only if pattern matches

by Kenosis (Priest)
on Jan 24, 2013 at 06:37 UTC ( #1015082=note: print w/replies, xml ) Need Help??

in reply to Print only if pattern matches

Place your matching regex in an if statement. If true, you can print your captures w/o error. The else can handle the exceptions:

use strict; use warnings; while (<DATA>) { next unless /^\d+\|(\d+?)\|/ and $1 == 1; if (/^(.*\|)*.*ABC\.pi=([\d.]+|[\w.]+)*.*ABC\.id=(\d+|[\w.]+).*$/) + { print "$1$2|$3\n"; } else { print "Exception: $_"; } }

Output on your data:

123|1|456464|645646|4546||789137136770 123|1|456464|645646|4546||789134713670 123|1|456464|645646|4546||789137213670 123|1|456464|645646|4546||78913713670 Exception: 123|1|456464|645646|4546|654~abc~dhghga~ +670 123|1|456464|645646|4546||78913713670 123|1|456464|645646|4546||78913713670 123|1|456464|645646|4546||789137135670 123|1|456464|645646|4546||789137153670 Exception: 123|1|456464|645646|4546|654~abc~dhghga~ +670 Exception: 123|1|456464|645646|4546|654~abc~dhghga~121322~456466874~87 +96896

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (7)
As of 2016-10-24 12:40 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (305 votes). Check out past polls.