bartrad has asked for the wisdom of the Perl Monks concerning the following question:
Hopefully a relatively simple one for somebody, but I've been staring at it too long it's all now a blur. I have the following output generated and it's either:
Output1
====================================================================== +======== LDP Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- ---------------------------------------------------------------------- +-------- No Matching Entries Found ====================================================================== +========
OR
Output 2
====================================================================== +======== LDP IPv4 Sessions ====================================================================== +======== Peer LDP Id Adj Type State Msg Sent Msg Recv Up Tim +e ---------------------------------------------------------------------- +-------- 1.1.1.1:0 Targeted Established 822443 822431 273d 15:02:2 +0 ---------------------------------------------------------------------- +-------- No. of IPv4 Sessions: 1 ====================================================================== +========
I'm trying to match using the following code to trigger an IF statement. Basically I'm looking for if the output contains an IP address then stop, otherwise keep going. But, it seems my IF statement returns true even if nothing that looks like an IP address is returned. I've been on regex101 to test my matching and it checks out there, but must be something obvious!
if ( $output1 || $output2 =~ m/\d+\.\d+/gm ) { print "Found something"; exit; } else { print "Do this instead";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regex match multiple line output
by hippo (Archbishop) on Feb 20, 2018 at 15:45 UTC | |
|
Re: Regex match multiple line output
by BillKSmith (Monsignor) on Feb 20, 2018 at 15:51 UTC | |
by bartrad (Beadle) on Feb 20, 2018 at 15:55 UTC | |
by AnomalousMonk (Archbishop) on Feb 20, 2018 at 17:07 UTC | |
|
Re: Regex match multiple line output
by thanos1983 (Parson) on Feb 20, 2018 at 16:10 UTC | |
|
Re: Regex match multiple line output
by Anonymous Monk on Feb 21, 2018 at 00:34 UTC |