in reply to Re: WGET equivalent
in thread WGET equivalent
there are a few errors which have me mystified. First, all the operations related to the file handle out cause a permission problem. the file in question has everyone with read and write access, so is there any clue what the issue is?#!/usr/local/bin/perl -w use strict; use CGI qw(:standard); use lib qw(/usr/lib/perl5/vendor_perl/5.8.6/LWP); use LWP::UserAgent; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); my $ua = LWP::UserAgent->new; $ua->timeout(10); $ua->agent('Mozilla/5.0'); print header(), start_html(); if( param() ){ my $page_num = param("page_num"); open(fd_s, "./random_sample") or &dienice("can't open input file f +or read: $ !"); my $line = 0; my $page = 0; my $current_page = ""; while(<fd_s>){ $line++; if( $line == $page_num){ last; } } close(fd_s); $current_page = $_; print "<h3>To see what the page $line currently looks like: <a hr +ef=$curren t_page>$_</a> </h3>\n"; $line++; chomp; print "<form action=\"random_200_sites.cgi\" method=\"POST\">\n"; print "<input type=\"hidden\" name=\"url\" value=\"$_\">"; print "<input type=\"hidden\" name=\"page_num\" value=\"$line\">"; print "<h3><input type=\"radio\" name=\"decision\" value=\"spam\" +onclick=\" this.form.submit()\">spam</h3>"; print "<h3><input type=\"radio\" name=\"decision\" value=\"nonSpam +\" onclick =\"this.form.submit()\">nonSpam</h3>"; print "<h3><input type=\"radio\" name=\"decision\" value=\"very ha +rd decide\ " onclick=\"this.form.submit()\">hard to decide</h3>"; print "</form>\n"; open(OUT, ">>web.result") or &dienice("Countn't open result output + file: $! "); my $decision = param("decision"); my $url = param("url"); if($decision eq "spam"){ print OUT "$url 1\n"; }elsif($decision eq "nonSpam"){ print OUT "$url 0\n"; }else{ print OUT "$url 2\n"; } close(OUT); print hr(); my $response = $ua->get($current_page); my $data = $response->content if($response->is_success); if($data){ print "page: $current_page\n$data\ndone", length($data); } }else{ print start_form(); print p("Starts from page ",textfield("page_num")); print p(submit("go")); print end_html; } sub dienice { my($errmsg) = @_; print "<h2>Error</h2>\n"; print "<p>$errmsg</p>\n"; print end_html; exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: WGET equivalent
by Corion (Patriarch) on Feb 01, 2008 at 19:20 UTC | |
by downer (Monk) on Feb 01, 2008 at 22:42 UTC | |
by Corion (Patriarch) on Feb 02, 2008 at 14:39 UTC | |
by downer (Monk) on Feb 04, 2008 at 15:55 UTC | |
by moritz (Cardinal) on Feb 04, 2008 at 17:32 UTC | |
by Corion (Patriarch) on Feb 04, 2008 at 17:33 UTC |