Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: search and replace

by bichonfrise74 (Vicar)
on Nov 04, 2009 at 17:46 UTC ( [id://805010]=note: print w/replies, xml ) Need Help??


in reply to search and replace

Is this what you want?
#!/usr/bin/perl use strict; while (<DATA>) { my ($word) = /\>(.*)\</; print "<con><p>$word</p></con><code> <br/>\n"; } __DATA__ <p>This is param1</p> <p>This is second para</p> <p>this is param3</p>

Replies are listed 'Best First'.
Re^2: search and replace
by Anonymous Monk on Nov 05, 2009 at 05:07 UTC
    <p>This is param1</p> <p>This is second para</p> <p>this is param3</p>
    The output should be
    <con><p>This is param1</p> <p>This is second para</p> <p>this is param3</p></con>
    Please tell me how to get the output this way
      printf("<con>%s</con>", do { local $/; <DATA> } ); __DATA__ <p>This is param1</p> <p>This is second para</p> <p>this is param3</p>

      Facetiousness aside, the DATA iteration isn't working the way you think/want and though there are plenty of tricks to get it to do what you're after in this context it's not a good practice; you should parse/edit XML with an XML parser/writer. XML::Twig and XML::LibXML are (generally) the favorites around these parts.

        __DATA__ <root> <p>This is param1</p> <p>This is second para</p> <p>this is param3</p> </root>
        How to search for the occurance of first <p> tag in a file and replace it with <con><p> and search for the last closing </p> tag and replace it with </p></con>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-24 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found