Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: match multi-lines from config file

by GrandFather (Saint)
on Aug 06, 2007 at 22:57 UTC ( [id://630921]=note: print w/replies, xml ) Need Help??


in reply to match multi-lines from config file

Use open to open a file handle then use:

while (<IN>) {

to scan the file. Use index or a regular expression match to skip (using next) until the interface line is found. Skip until the description line is found:

/^description/ && last while <IN>; my $description = $_;

Process the description then use the same technique for the rest of the lines you need to match.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: match multi-lines from config file
by mreece (Friar) on Aug 07, 2007 at 06:23 UTC
    /^description/ && last while <IN>;
    that confused the heck out of me! how about this form?
    $_ = <IN> until /^description/;
    doh!

      Because that tests $_ before the first value is assigned to it and doesn't terminate for a file that doesn't include a matching line!


      DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://630921]
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-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found