I wrote the following script to extract some information from a web page and print it to the screen. The web page is absolutly basic HTML so my paltry regexp works fine.
The problem is in the print statements at the end wherein I attempt to print out the information I extracted. As shown below, the script only prints out the contents of $avg_size. If I uncomment all but any of the variables, it prints out correctly.
I have tried forcing the screen to autoflush using the STDOUT->autoflush(1) method of the FileHandle module and by setting $| = 1. Neither option had any effect.
#!/usr/bin/perl -w
use strict;
use LWP::Simple;
#### retrieve web page
my $url = "http://www.visionforum.com/admin/avantgo.asp";
my $page_content = get($url);
#### remove extraneous information and HTML markup
(my $plain_text = $page_content) =~ s/<[^>]*>//gs;
#### extract relevant info
my @lines = split /\n/, $plain_text;
my $title = $lines[10];
my $timestamp = $lines[11];
my $shoppers = $lines[13];
my $num_orders = $lines[17];
my $gross_sales = $lines[18];
my $avg_size= $lines[20];
#### output
print $title;
print $timestamp;
print $shoppers;
print $num_orders;
print $gross_sales;
print $avg_size;
exit;
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|