Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Formatting an array

by AnomalousMonk (Archbishop)
on Feb 08, 2018 at 02:00 UTC ( [id://1208672]=note: print w/replies, xml ) Need Help??


in reply to Formatting an array

Maybe something like:

c:\@Work\Perl\monks>perl -wMstrict -le "use Regexp::Common qw(net); ;; my @strings = ( '/data/alcatel_7750/routername1- static-route 1.1.1.1/30 next- +hop 2.2.2.2 tag 624', '/data/alcatel_7750/routername2- static-route 1.1.1.3/30 next- +hop 3.3.3.3 tag 624', '/data/alcatel_7750/routername3- static-route 1.1.1.2/30 next- +hop 4.4.4.4 tag 628', ); ;; my $rx_ipv4_dotted_dec = qr{ (?<! \d) $RE{net}{IPv4} (?! \d) }xms; my $rx_routename = qr{ \b [[:alpha:]] \w* \b }xms; my $rx_route = qr{ \b [[:alpha:]] [[:alpha:]-]* \b }xms; ;; for my $s (@strings) { my $parsed = my ($r_name, $r_ip) = $s =~ m{ / ($rx_routename) - \s+ ($rx_route \s+ $rx_ipv4_dotted_dec / \d+) }xms; ;; die qq{bad record: '$s'} unless $parsed; ;; print qq{'$s' -> \n ($r_name) ($r_ip)}; } " '/data/alcatel_7750/routername1- static-route 1.1.1.1/30 next-hop + 2.2.2.2 tag 624' -> (routername1) (static-route 1.1.1.1/30) '/data/alcatel_7750/routername2- static-route 1.1.1.3/30 next-hop + 3.3.3.3 tag 624' -> (routername2) (static-route 1.1.1.3/30) '/data/alcatel_7750/routername3- static-route 1.1.1.2/30 next-hop + 4.4.4.4 tag 628' -> (routername3) (static-route 1.1.1.2/30)


Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-23 22:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found