LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Perl - Tpl file - Need to replace new line character. (http://www.linuxquestions.org/questions/programming-9/perl-tpl-file-need-to-replace-new-line-character-227774/)

knnirmal 09-07-2004 01:29 PM

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.

Cedrik 09-07-2004 01:41 PM

You can also use tr to delete one char :

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

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

will do

knnirmal 09-07-2004 03:27 PM

Have found solution:

Following code works fine. Thanks to all of u..
<iw_perl><![CDATA[

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

iwpt_output("newdocument.write('$str');");

]]>
</iw_perl>


All times are GMT -5. The time now is 04:06 PM.