cajun has asked for the wisdom of the Perl Monks concerning the following question:

I got this piece of code from here a while back. (I looked for the code again to give the author credit, but couldn't find it) I modified it to work in a browser (one line, big mod).

If I run this from a terminal window, everything works as it should, i.e.:

node 1

node 2

node 3

However, if I run it from within a browser, the nodes are displayed as follows:

node 1 node 2 node 3

I've looked at it and haven't been able to figure out the difference yet. Can someone please explain ?

#!/usr/bin/perl -w use LWP::Simple; $/ = undef; my $slurp = get("http://www.perlmonks.org/headlines.rdf"); push @node, [$1,$2] while $slurp =~ /<item>\s*<title\s*>([^<]*)<\/title>\s*<link\s*>([^< + +]*)/gio; print "Content-type: text/html\n\n"; print map { "<a href=\"$_->[1]\">$_->[0]</a>\n" } @node;
Thanks !

Replies are listed 'Best First'.
Re: perlmonks-topstories
by extremely (Priest) on Oct 07, 2000 at 13:36 UTC
    Do a viewsource, you'll see the returns. =) You forgot that webbrowsers eat whitespace and treat returns as space...

    --
    $you = new YOU;
    honk() if $you->love(perl)

RE: perlmonks-topstories
by turnstep (Parson) on Oct 07, 2000 at 17:33 UTC

    Four quick "solutions":

    • Change the content type to "text/plain"
    • Surround the code with <PRE> tags.
    • Change all newlines to <BR> tags.
    • HTML format it, probably by putting a <LI> tag at the start of every line.
Re: perlmonks-topstories
by cajun (Chaplain) on Oct 08, 2000 at 23:06 UTC

    Thanks extremely & turnstep for the pointers and 'solutions'.