Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Store multiple lines

by johngg (Abbot)
on Feb 09, 2018 at 14:41 UTC ( #1208834=note: print w/replies, xml ) Need Help??

in reply to Store multiple lines

If it is safe to assume that the "service-name" line immediately follows the "static-route" line, and the file is not huge, then I might read all of the data into a scalar then remove the \nxxxxxxxx- parts globally so that all the information for each item was on one line. That would remove the need for the logic of two separate regex matches simplifying the data extraction. I would then open a reference to the scalar and read that line by line. Something like:-

use strict; use warnings; open my $inFH, q{<}, \ <<EOD or die qq{open: < \ HEREDOC: $!\n}; dnsname1: static-route next-hop preferen +ce 200 bfd-enable tag 685 dnsname1- service-name "XYZ12345-s12345" dnsname2: static-route next-hop bfd-enab +le tag 635 dnsname2- service-name "XYZ67891-s67890" EOD my $data = do { local $/; <$inFH>; }; close $inFH or die qq{close: < \ HEREDOC: $!\n}; $data =~ s{\n\S+-}{}g; open $inFH, q{<}, \ $data or die qq{open: < \ scalar: $!\n}; while (<$inFH> ) { # Do a single data extraction regex here. ... } close $inFH or die qq{close: < \ scalar: $!\n};

I hope this is helpful.



Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1208834]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (5)
As of 2018-02-23 18:29 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (306 votes). Check out past polls.