Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: Store multiple lines

by johngg (Canon)
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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (3)
As of 2020-10-31 07:29 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (287 votes). Check out past polls.