I'm pretty knew to perl and I've looked around for awhile, and I cant seem to find a solution to my problem. My problem has to do with LWP::Simple and CGI.PM I wrote a simple script that fetches a webpage then it parses the webpage( to get some information from it. Then I Output this data using CGI.PM. From the command line the script outputs everything perfectly, but when I run it from a browser none of the data I parsed from the webpage makes it in the browser window. Im running this on solaris and apache, it's a university server, I had to install the LWP module privately to my home directory, it wasn't installed on the system. Below is the script it's not very long. Thanks, Keegan

#!/usr/bin/perl # use warning; use CGI; use CGI::Pretty; use strict; use lib qw(/home/001/d/da/dale81/LWP/lib/perl5/site_perl/ /home/001/d/da/dale81/LWP/lib/perl5/site_perl/LWP/); use LWP::Simple; my $fdata = CGI->new(); print $fdata->header; print $fdata->start_html('Weather'); my $zip = 75252; my $url1 = 'http://www.wunderground.com/cgi-bin/findweather/getForecas +t?query='; my $url = $url1.$zip; my $response =get( $url ); my $day01; my $day02; my $day03; my $day04; my $day05; my $fTemp; my $cTemp; #extract 5-day outlook if($response=~/<th(.+)>([a-zA-Z]+)<\/th>(\s)<th(.+)>([a-zA-Z]+)<\/th>( +\s)<th(.+)>([a-zA-Z]+)<\/th>(\s)<th(.+)>([a-zA-Z]+)<\/th>(\s)<th vali +gn=middle class=smalltable width="20%" bgcolor=#DDDDDD>([a-zA-Z]+)<\/ +th>/i) { $day01=$2; $day02=$5; $day03=$8; $day04=$11; $day05=$13; } #output days as headings print $fdata->h1($day01); print br; print $fdata->h1($day02); print br; print $fdata->h1($day03); print br; print $fdata->h1($day04); print br; print $fdata->h1($day05); print br; #extract temp data if($response=~/<nobr><b>([0-9]+)<\/b>&nbsp;&#176\;F<\/nobr>(\s+)\/(\s+ +)<nobr><b>([0-9]+)<\/b>&nbsp\;&#176;C<\/nobr>/i) { $fTemp=$1; $cTemp=$4; } #output temperature print "Temperature F=", $fTemp; print br; print "Temperature C=", $cTemp; print br; print $fdata->end_html;

2004-12-07 Janitored by Arunbear - added readmore tags, as per Monastery guidelines


In reply to LWP::simple and CGI not displaying correctly by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.