Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Match pattern per line and after another one as multiline in single file opening

by kennethk (Abbot)
on Feb 14, 2017 at 19:42 UTC ( [id://1181992]=note: print w/replies, xml ) Need Help??


in reply to Match pattern per line and after another one as multiline in single file opening

You are right that there is unnecessary disk access going on. There are cute/clever ways to do this (e.g. piping in from grep), but the easiest way would be swap your print statement with a concatenation:
open my $FH, '<' , $config or die "Cannot open $config: $!\n"; my $data = <$FH>; # Dump the line $data = ''; while (<$FH>) { next if /^\s*#|^$/; $data .= $_; } close $FH; while ($data =~ m/\{([^}]*)\}/gx ) { print "$1\n"; }
Incidentally, you have a $data = <$FH>; peppered into your first chunk. Are you meaning to dump the first line of the file? I've included that behavior, but it smells buggy to me.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-28 22:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found