Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-07-2004, 12:29 PM   #1
LQ Newbie
Registered: Sep 2004
Posts: 2

Rep: Reputation: 0
Unhappy Perl - Tpl file - Need to replace new line character.

Hi, m brand new to Perl programming..

We have one .tpl file, which has code to read data from xml file and generate html using this data.

xml data has new line characters. We want to remove this new line character before generating html file.

Following is javascript code which is creating prob:

newdocument.write('<iw_value name='dcr.Important Information' />');

Here '<iw_value name='dcr.Important Information' />' returns string having new line character.
Old 09-07-2004, 12:41 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 243Reputation: 243Reputation: 243
You can also use tr to delete one char :

cat xml_file.xml | tr -d '\n' >

or if the file is read line by line inside Perl script, just :
chop $line;

will do

Last edited by Cedrik; 09-07-2004 at 12:43 PM.
Old 09-07-2004, 02:27 PM   #3
LQ Newbie
Registered: Sep 2004
Posts: 2

Original Poster
Rep: Reputation: 0
Have found solution:

Following code works fine. Thanks to all of u..

my $str = iwpt_dcr_value( 'dcr.Important Information' );
$str =~ s/\n/<br \/>/g;
$str =~ s/\'/\\'/g;




Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python: find defined text string in a file, and replace the whole line Dark Carnival Programming 6 05-22-2007 06:02 AM
problem in perl replace command with slash (/) in search/replace string ramesh_ps1 Red Hat 4 09-10-2003 01:04 AM
PERL:: trying to remove last line of file ocularbob Programming 16 09-01-2003 01:07 PM
trying to search and replace text file for single & multiple line breaks separately brokenfeet Programming 7 08-29-2003 01:56 PM
perl: replacing a special line in a file markus1982 Programming 1 09-26-2002 02:05 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration