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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

This might be what you're after, but it's probably fragile and definitely still horribly messy. I wouldn't start from where you are, in all honesty.

use strict; use warnings; my @grep = <DATA>; my $ip = 'whatever'; if (@grep) { my $hop; my $static; my $tag; my $vpna; my $dns; my %results; print "\nFound some static routes...\n"; while (my $line = shift @grep) { if ($line =~ m/^(\S+):\s+static-route (\S+) next-hop (\S+)( preference +\d+|)( bfd-enable|) tag (\d+)/ ) { ($dns, $static, $hop, $tag) = ($1, $2, $3, $6); $line = shift @grep; $line =~ m/^(\S+)-\s+service-name (\S+)/; $vpna = $2; $results{$dns}{$vpna}{$static}{$hop} = $tag; } } #print Dumper \%results; for my $box (keys %results) { print "\n$box\n"; for my $service (keys %{$results{$box}}) { for my $static (keys %{$results{$box}{$service}}) { for my $hop (keys %{$results{$box}{$service}{$static}} +) { print "$static\t next-hop $hop\t"; print "tag $results{$box}{$service}{$static}{$hop}, se +rvice $service\n"; print "\n"; } } } } } else { print "No static routes exist for $ip\n"; } __DATA__ dnsname1: static-route 1.1.1.1/30 next-hop 2.2.2.2 preferen +ce 200 bfd-enable tag 685 dnsname1- service-name "XYZ12345-s12345" dnsname2: static-route 3.3.3.3/30 next-hop 4.4.4.4 bfd-enab +le tag 635 dnsname2- service-name "XYZ67891-s67890"

In reply to Re: Store multiple lines by hippo
in thread Store multiple lines by bartrad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others contemplating the Monastery: (3)
    As of 2019-10-21 05:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      Notices?