Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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 meditating upon the Monastery: (5)
As of 2015-10-06 23:18 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (163 votes), past polls