For Programmers: Free Programming Magazines  


Home > Archive > PERL Miscellaneous > March 2008 > Inserting new line to a string









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Inserting new line to a string
Deepan Perl XML Parser

2008-03-24, 4:20 am

Hi all,
I am having a string like below:



<responseStatus>HTTP/1.1 200 OK</responseStatus>

<cookies></cookies>

<headers>

<header name="Accept-Ranges">bytes</header>

<header name="Content-Encoding">gzip</header>

<header name="Content-Length">5375</header>

<header name="Content-Type">text/html</header>

<header name="Date">Wed, 19 Mar 2008 10:00:30 GMT</header>

<header name="ETag">"1667999478"</header>

<header name="Last-Modified">Wed, 19 Mar 2008 10:00:01 GMT</header>

<header name="Server">Cricbuzz- Blazing Fast</header>

<header name="Vary">Accept-Encoding</header>

</headers>

<content>

<contentLength>17958</contentLength>

<compression>70.069</compression>

<encodingScheme>gzip</encodingScheme>

<text><![CDATA[

<html>..<head>...</body>..<!-- The template body ends -->..</html>.

]]></text>

<mimeType>text/html</mimeType>

</content>



------------------------------------------------

I want to insert new line at the end of every end tag[ex:- </
responseStatus>].

Thanks,
Deepan
Gunnar Hjalmarsson

2008-03-24, 8:08 am

Deepan Perl XML Parser wrote:
> I am having a string like below:


<html markup snipped>

> I want to insert new line at the end of every end tag[ex:- </
> responseStatus>].


Even if I can't see the point, it's easily done using the s/// operator.

perldoc perlop (about the s/// operator)
perldoc perlrequick (about regular expressions)
perldoc perlretut ("- )
perldoc perlre ("- )

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Ben Bullock

2008-03-24, 10:20 pm

On Mar 24, 5:58 pm, Deepan Perl XML Parser <deepan...@gmail.com>
wrote:
> I am having a string like below:


> I want to insert new line at the end of every end tag[ex:- </
> responseStatus>].


$mystring =~ s/<\//<\/\n/g;

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com