Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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
Comment on Re: Print only if pattern matches
Select or Download Code

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 musing on the Monastery: (4)
As of 2016-04-30 04:04 GMT
Find Nodes?
    Voting Booth?
    :nehw tseb si esrever ni gnitirW

    Results (441 votes). Check out past polls.