Forum Moderators: coopster & phranque

Message Too Old, No Replies

Removing line break

remove line break from script output

         

planbeta

5:52 pm on May 9, 2003 (gmt 0)

10+ Year Member



Hi

I have a small script that reads a text/flat file database and creates links from the returned results. It works fine except it is including the breaks in the results to which is messing up the html:

Here's the script:
----------------------------------
#!/usr/bin/perl
print "Content-type:text/html\n\n";

open(INFO, "../list.txt");
@array=<INFO>;
close (INFO);

foreach $keyword(@array){
$keywordhypen=$keyword;
$keywordhypen=~tr/ /-/;
$keystring='<a href="'.$keywordhypen.'.html">'.$keyword.'</a><br>';
print<<End_of_File;
$keystring
End_of_File
}
----------------------------------

which produces html like:

<a href="word-one
.html">word one
</a><br>
<a href="word-two
.html">word two
</a><br>

As you can see everytime one of the variables is printed it also prints a new line break. Is there anyway to make it so the code prints this instead:

<a href="word-one.html">word one</a><br>
<a href="word-two.html">word two</a><br>

I have NO idea how you would.

Cheers

Chris

DrDoc

5:55 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Before this line:
$keywordhypen=$keyword;
add this:
chop($keyword) if $keyword =~ /\n$/;

planbeta

5:59 pm on May 9, 2003 (gmt 0)

10+ Year Member



Brilliant that's sorted the problem - thanks!

Feel stupid for asking when you see the answer - easy when you know how huh!?

DrDoc

6:25 pm on May 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't feel stupid... We're all somewhere in the progress of learning :)