StarkRavingCalm has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that will be used in a larger script but this part is giving me some trouble.
My goal for this part of the script is to perform a file listing on a webpage and into a hash with filename as key and file size as value.But I have been unable to find a way to get filesize so I have tried to do it with just an array of filenames.
Here is the code as it currently stands, the issue is that it only prints the last element outside the loop, inside the loop it prints all of them. If anyone has a way to get it work with a hash as mentioned above, I'd rather that than messing with the array problem.#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use HTML::TokeParser; use LWP::Simple; use File::Basename; use List::Compare; ## POC URL: my $page=get('http://localhost/images'); my %urlhash; my @urlfiles; my @array; my @newarray; my $p= HTML::TokeParser->new(\$page); while (my $token = $p->get_tag("a")) { @array = $token->[1]{href} || "-"; my $text = $p->get_trimmed_text("/a"); ## Just a few lines of crap cleaner... for (@array) {s/test.txt//g}; for (@array) {s/\///g}; for (@array) {s/\?C\=N;O\=D//g}; for (@array) {s/\?C\=M;O\=A//g}; for (@array) {s/\?C\=S;O\=A//g}; for (@array) {s/\?C\=D;O\=A//g}; #print "@array\n"; } print "@array\n";
The crap cleaner section is to remove that from the webpage. I have removed it on my POC Apache server, but it exists on the server I will run it against, which I have no control over.
Thanks in advance!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with Toke Parser
by tangent (Parson) on Oct 27, 2015 at 21:08 UTC | |
by Anonymous Monk on Oct 28, 2015 at 01:32 UTC | |
|
Re: Help with Toke Parser
by stevieb (Canon) on Oct 27, 2015 at 20:52 UTC |