Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
First off, what did you try so far? Please read Is PM a good place to get answers for homework?.

Then, what you are referring to as paragraphs in your example are lines. This may seem picky, but the distinction between lines and paragraphs makes sense. There is a paragraph mode reading files. See perlrun, there the switch -0 and the special value 00 for it.

blah blah blah #line \ blah blah blah #line - paragraph blah blah blah #line / <--- paragraph separator blah blah blah #line \ blah blah blah #line - paragraph blah blah blah #line /

I would do this:

#!/usr/bin/perl $file = shift; open(I,"<$file"); local $/; $_ = <I>; s|<list>(.*?)</list>|"<list>".join("\n",map{"<item>$_</item>"} split"\n",$1)."</list>"|ges; print;
Note that the "\n" for join and split should be "\r\n" for Windows and "\r" for Mac systems.

You can stuff that into a one-liner:

perl -p00 -e 's|<list>(.*?)</list>|"<list>".join("\n",map{"<item>$_</i +tem>"}split"\n",$1)."</list>"|ges;' textfile
Now go and read perlre and perlvar.

greets,
--shmem

_($_=" "x(1<<5)."?\n".q/)Oo.  G\        /
                              /\_/(q    /
----------------------------  \__(m.====.(_("always off the crowd"))."
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Regex to replace a particular part of content by shmem
in thread Regex to replace a particular part of content by rsriram

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2022-08-10 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?