I have a LWP problem causing a JavaScript Unterminated String Constant
error.

The goal is to put some stock quote information in a JavaScript array for
use in a web page.

The problem is that a line break gets inserted in the stocktext[1] variable
(through $line).

Can someone help me get rid of the unwanted line break?


Here's the code:

#---Begin code---------------------------------------
#!/usr/local/bin/perl

select(stdout);
$| = 1;
print "Content-type: text/html\n\n";
use LWP::UserAgent;
$Web_agent = new LWP::UserAgent;
my $req = new HTTP::Request GET =>
'http://quote.canada-stockwatch.com/sw/custom/textq.cfm?pw=cms44tuv91';
my $res = $Web_agent->request($req);
my @lines_ouput = ();
my $line;

if ($res->is_success)

        {
        @lines_ouput = split(/\n/,$res->content);

print "<script language='JavaScript' type='text/javascript'> \n";
print "var stocktext = new Array(3); \n";

        foreach $line (@lines_ouput)

                {

                if ($line =~ /chartf\.stockwatch\.com\/c\/C/)
                        {
                        $firstText = 'stocktext[1] = "' . $line . '";';
                        print $firstText;
                        print "\n";
                        }

                else
                        {
                        $newline = "";
                        print $newline;
                        }
                }

print "</script> \n";

        }
else
        {
        print "<H2>Houston, we have a problem</H2>\n";
        }
exit(0);

#--End code--------------------------------------------

Best regards,


Fran�ois Nadeau
www.cloudraker.com
T. 514.499.0005 ext:230
F. 514.499.0525

Reply via email to