Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Screen buffering mystery

by Albannach (Prior)
on Dec 22, 2001 at 01:22 UTC ( #133885=note: print w/replies, xml ) Need Help??


in reply to Screen buffering mystery

As grep says, you are printing everything, but there are no newlines in any of those variables since split removes them. The output variables overwrite each other because each ends in a carriage return character (this can often be seen in the output as the one line you do get sometimes has garbage at the end left over from previous lines). One solution which builds on grep's and adds a somewhat simpler print statement follows:
my @lines = map{"$_\n"} split /\r\n/, $plain_text; print @lines[10,11,13,17,18,20];
If you want to keep the meanings of the various line numbers intact in the code, but avoid creating independent variables for that purpose, you could do something like the following:
use strict; use LWP::Simple; my %info_lines = ( title => 10, timestamp => 11, shoppers => 13, num_orders => 17, gross_sales => 18, avg_size => 20, ); my $url = "http://www.visionforum.com/admin/avantgo.asp"; my $page_content = get($url); (my $plain_text = $page_content) =~ s/<[^>]*>//gs; my @lines = map{"$_\n"} split /\r\n/, $plain_text; print $lines[$_] for sort values %info_lines;

--
I'd like to be able to assign to an luser

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://133885]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (8)
As of 2020-02-19 00:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?










    Results (80 votes). Check out past polls.

    Notices?