multiline regex

Discussion in 'Perl Misc' started by Mike Jackson, Oct 13, 2003.

  1. Mike Jackson

    Mike Jackson Guest

    Hi,
    I would like to convert this block of text:

    (app "webserver"
    (ip "1.2.3.4")
    (name "foo")
    (host "somehost")
    )


    to this:

    app.webserver.ip="1.2.3.4";
    app.webserver.name="foo";
    app.webserver.host="somehost";


    and skip processing of the entire block if the top level contains a
    "no", for example:

    (some_condition "no"
    (foo "")
    (bar "")
    )


    Is there already some method of doing this in perl, or is this a regex
    job? Any advice?

    Thanks,
    Mike
     
    Mike Jackson, Oct 13, 2003
    #1
    1. Advertising

  2. Mike Jackson

    Anno Siegel Guest

    Mike Jackson <> wrote in comp.lang.perl.misc:
    > Hi,
    > I would like to convert this block of text:
    >
    > (app "webserver"
    > (ip "1.2.3.4")
    > (name "foo")
    > (host "somehost")
    > )
    >
    >
    > to this:
    >
    > app.webserver.ip="1.2.3.4";
    > app.webserver.name="foo";
    > app.webserver.host="somehost";
    >
    >
    > and skip processing of the entire block if the top level contains a
    > "no", for example:
    >
    > (some_condition "no"
    > (foo "")
    > (bar "")
    > )
    >
    >
    > Is there already some method of doing this in perl, or is this a regex
    > job? Any advice?


    What have you tried so far?

    We help writing scripts, but we're not in the business of delivering
    to specification.

    You have nested parentheses to parse, so Text::Balanced will probably
    figure in the solution.

    Anno
     
    Anno Siegel, Oct 13, 2003
    #2
    1. Advertising

  3. Mike Jackson

    Mike Jackson Guest

    Anno Siegel wrote:

    >
    > You have nested parentheses to parse, so Text::Balanced will probably
    > figure in the solution.


    Hi,
    That was all I asked and all I wanted to know, e.g. was there already
    a module that could assist in this task, or was it purely a regex task.
    Thanks for the tip :) I'm sure that it will save me some time.

    Thanks,
    --
    mike
     
    Mike Jackson, Oct 13, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Yatima

    Multiline regex help

    Yatima, Mar 3, 2005, in forum: Python
    Replies:
    13
    Views:
    580
    Kent Johnson
    Mar 4, 2005
  2. eggie5

    multiline regex expression

    eggie5, Jul 21, 2007, in forum: Java
    Replies:
    4
    Views:
    524
    Roedy Green
    Jul 22, 2007
  3. Gilles Ganault

    [2.5] Regex doesn't support MULTILINE?

    Gilles Ganault, Jul 22, 2007, in forum: Python
    Replies:
    9
    Views:
    330
    Gilles Ganault
    Jul 24, 2007
  4. Replies:
    3
    Views:
    833
    Reedick, Andrew
    Jul 1, 2008
  5. dale zhang
    Replies:
    8
    Views:
    458
    Tintin
    Nov 30, 2004
Loading...

Share This Page