[15590] in Perl-Users-Digest
Perl-Users Digest, Issue: 3003 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 10 11:05:27 2000
Date: Wed, 10 May 2000 08:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <957971109-v9-i3003@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 10 May 2000 Volume: 9 Number: 3003
Today's topics:
Re: #How to parse and strip perl comments? (Bart Lateur)
'System' command wont adduser <dhopkins@itribe.net>
Re: a cgi.pm question - carrying variable state across <ejwhite1@facstaff.wisc.edu>
comparing a folder full of files to a comma,separated l <nospam@devnull.com>
conversion hex->ascii, ascii->mif, oder hex->mif <Matthias.Kleine@prs.de>
Re: File Upload Script <flavell@mail.cern.ch>
Re: File Upload Script <jeff@vpservices.com>
Re: Gotta be in the FAQ...but it doesn't seem to be... <flavell@mail.cern.ch>
Re: Gotta be in the FAQ...but it doesn't seem to be... <jeff@vpservices.com>
How to parse CGI input with perl 5.003 (was Re: How can <jeff@vpservices.com>
Re: how to use fork or background processing (in Perl/T (Clinton A. Pierce)
Re: how to use fork or background processing (in Perl/T <michael.schlueter@philips.com>
Re: Inserting text in a chart scarey_man@my-deja.com
Re: Is Perl fast enough? (Tad McClellan)
Re: Is Perl fast enough? <nospam@devnull.com>
Problem processing multiple files mfelps@my-deja.com
Re: Proper use of resources (was Re: more regexp madnes <nospam@devnull.com>
Re: Pulling my hair out! vlad55@my-deja.com
Recursive copy (Skip links) <schapal@mail.jonesctr.org>
Re: sort a two-dimensional array.... <mjcarman@home.com>
Re: URGENT HELP WITH REGEXP REQUIRED <billy@arnis-bsl.com>
Re: using Perl's RE to do basic manipulation of a flex <ronnie@catlover.com>
Re: Win32 SYSTEM window (Clinton A. Pierce)
Re: windos equivalent of fork ??? (Clinton A. Pierce)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 10 May 2000 13:04:45 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: #How to parse and strip perl comments?
Message-Id: <391a5dde.20558647@news.skynet.be>
Peter Hill wrote:
>Jonathan Stowe wrote:
>> fortune oscar homer
>You're right, of course, how could you argue with an educated gentleman
>who quotes Homer?
Is that the acient Greek writer, AKA Homeros, or Homer Simpson?
--
Bart.
------------------------------
Date: Wed, 10 May 2000 09:51:23 -0400
From: "Derrick Hopkins" <dhopkins@itribe.net>
Subject: 'System' command wont adduser
Message-Id: <shiqdg94d58158@corp.supernews.com>
I have a program that gets run by a cron job every 15 minutes. One of the
functions of the program is to add new users that are listed in a text file.
I'm trying to do it using the 'system' command. But it's not working. Here's
the subroutine.
sub add_user($fulldomain)
{
$username = $theusername;
$password = $thepassword;
$command = "adduser -d /www/htdocs/$fulldomain -s /bin/nologin -g web -m -k
/www/tmpdomain -p $password $username";
$add = system($command);
print "$add : $command \n";
}
I thought the problem was that it wasn''t being run as root. But program is
owned by root and the cronjob that runs it is owned by root. Plus, earlier
in the program, it creates files which show up as being owned by root.
D
--
Derrick Hopkins[]dhopkins@itribe.net
Enjoy Your Job - Make Lots of Money - Work Within the Law -
Pick Any 2
------------------------------
Date: Wed, 10 May 2000 09:52:41 -0500
From: "Eric J. White" <ejwhite1@facstaff.wisc.edu>
Subject: Re: a cgi.pm question - carrying variable state across multiple invocations of the same script
Message-Id: <391977B9.E3CF5CFB@facstaff.wisc.edu>
Jeff Zucker wrote:
> "Eric J. White" wrote:
> >
> > I'm trying write a script that will allow me to present a series of web
> > pages that will change based on the values of responses given to earlier
> > pages.
>
> > ... I want to refer to variables defined in the
> > page 1 subroutine during the creation of page 3. Is there a way that I
> > can carry the state of the page 1 variables through each time the script
>
> You've got the basic idea. The only thing you are missing is the
> conecpt of hidden fields. When you get the parameter for "sex" from
> page 1, stick it in a hidden field on all succeeding forms that need the
> info and it will be passed along. Since forms are by default "sticky"
> the value for sex will be added to each hidden field automatically
> without you even having to supply a value (assuming, of course, that you
> keep the name of the field the same).
>
> > sub print_form2 {
> > ...
> > "SEX = $SEX",
>
> Add: hidden(-name=>'sex),
>
> Then in form three param('sex') will contain the value the user put in
> form one. And keep adding the same hidden field in all the forms that
> you want to keep passing that value on.
>
> --
> Jeff
Thanks Jeff,
Putting all the vars I want to carry over from page to page in hiddne fields
works great. Now I'm wondering if there's a way to do it w/o having to name
each var individually on each page. I'm going to end up with 100 or so vars
that I want to carry over, so it's be nice to be able to just add each page's
vars to an array or a hash. I've treid this but it doesn't seem to work. Any
'foreach' construction that I use seems to only carry over the vars from the
previous page, once again dropping, say the page 1 vars at page 3.
Below is the code I'm working with, with the failed 'foreach' blocks in sub_2
and sub_3. Any chance I can do what I'm describing?
Thanks a lot,
Eric
current code:
#!c:\perl\bin\perl.exe -w
# Script: p9258.pl
use CGI ':all';
use warnings;
$action=param('action');
(%allvars);
#foreach $name ( param() ) {
# $value = param($name);
# print "The value of $name is $value\n";
#}
#each time we invoke this script we need to test
#the value of $action so we know which page to
#display next
#execute the correct subroutine
if ($action eq "Onto page 2") {
sub_2();
} elsif ($action eq "Onto page 3") {
sub_3();
}else {
sub_1();
}
#print the right page
if ($action eq "Onto page 2") {
print_form2();
} elsif ($action eq "Onto page 3") {
print_form3();
} else {
print_form1();
}
#here we've got the subroutines that print the pages.
#there's one for each page
sub print_form1 {
print header,
start_html('p9258 Page 1 - Demographics'),
h1('Demographic Information');
print start_form,
"Please enter your ID: ",
textfield(-name=>'ID', -maxlength=>10, ),
p,
p,
"If you've answered the demographic questions on an earlier vist please",
" press the 'Onto page 2' button at the bottom of this page.",
p,
p,
hr,
"In order to assist us in our statistical analysis of the data",
"we are collecting in this study, we have included a set of questions",
"asking for general demographic information about you, including",
"questions about your level of experience in the fields of social",
"work and child welfare as well as more basic data like your age,",
"sex, race/ethnicity, etc.",
p,
p,
strong("1. "),
"What is your sex? ",
radio_group(-name=>'sex', -values=>['1', '2'], -labels=>{'1'=>'male',
'2'=>'female'}),
p(),
strong("2. "),
"What is your highest level of education? ",
p,
popup_menu(-name=>'education', -values=>['1', '2', '3', '4', '5', '6', '7'],
-labels=>{'1'=>'Less than bachelors',
'2'=>'Bachelors in SW',
'3'=>'Bachelors in other field',
'4'=>'Masters in SW',
'5'=>'Masters in other field',
'6'=>'PhD or Professional Doctorate',
'7'=>'Other'}),
p(),
hidden(-name=>'sex'),
hidden(-name=>'education'),
submit(-name=>'action', -value=>'Onto page 2'),
end_form;
}
sub print_form2 {
print header,
start_html('p9258 Page 2 - Household Member Information'),
h1('Household Member Information');
#foreach $name ( param() ) {
# $value = param($name);
# print "The value of $name is $value\n";
#}
foreach $key (keys %allvars) {
print "For $key we have a value of $allvars{$key}\n";
}
print start_form,
"Please tell us who's living in the household:",
p,
p,
strong("10. "),
"Is the biological mother in the household now?",
p,
radio_group(-name=>'bioMom', -values=>['1', '2'], -labels=>{'1'=>'Yes',
'2'=>'No'}),
p(),
# hidden(-name=>'ID'),
# hidden(-name=>'sex'),
# hidden(-name=>'education'),
# hidden(-name=>'bioMom'),
submit(-name=>'action', -value=>'Onto page 3'),
end_form;
}
sub print_form3 {
print header,
start_html('Page 3'),
h1('THIS IS PAGE 3');
foreach $key (keys %allvars) {
print "For $key we have a value of $allvars{$key}\n";
}
#foreach $name ( param() ) {
# $value = param($name);
# print "The value of $name is $value\n";
#}
print start_form,
"This is page 3: ",
p(),
submit(-name=>'action', -value=>'Submit completed form'),
end_form;
}
#here we've got the subroutines that are run after
#each page is submitted.
sub sub_1 {
}
sub sub_2 {
foreach $name ( param() ) {
$value=param($name);
$allvars{$name} = $value;
}
# foreach $name ( param() ) {
# hidden(-name=>$name);
# }
}
sub sub_3 {
# foreach $name ( param() ) {
# hidden(-name=>$name);
# }
foreach $name ( param() ) {
$value=param($name);
$allvars{$name} = $value;
}
}
------------------------------
Date: 10 May 2000 14:28:15 GMT
From: The WebDragon <nospam@devnull.com>
Subject: comparing a folder full of files to a comma,separated list
Message-Id: <8fbrlv$hl9$0@216.155.32.13>
I have a script
#!perl -w
use strict;
use diagnostics -verbose;
use File::Spec;
my $readFile = File::Spec->catfile( File::Spec->curdir(),
'maps_list.txt');
my $inputDir = File::Spec->catfile( File::Spec->curdir(), 'Maps', '');
opendir(DIR, $inputDir) || die "can't opendir $inputDir: $!";
my @filesList = readdir(DIR);
closedir DIR;
open(GET, "<$readFile") or die ("can't open $readFile : $!");
BIGLOOP: foreach my $files (@filesList) {
$files =~ s/.zip//g;
SMLOOP: foreach my $lines (<GET>) {
if (REGEXP_GOES HERE) {
print "$lines\n";
}
}
}
close (GET);
-=-
all the files in maps end with '.zip' so I have the script stripping
them off ..
all the lines in maps_list.txt look like this
--BEGIN ut_assault_maps.htm --
--
"as-abraxasassault","AS-AbraxasAssault",1288,"as-abraxasassault",8
"as-airportterror","AS-AirportTerror",922,"as-airportterror",4.5
[snip]
"as-urbanassault","AS-UrbanAssault",2424,"-1",-1
--
--END--
--
--BEGIN ut_capturetheflag_maps.htm --
--
"ctf-2fort","CTF-2Fort",221,"-1",-1
"ctf-2fort5","CTF-2Fort5",781,"-1",-1
[snip]
"ctf-worldscollide","CTF-WorldsCollide",1367,"-1",-1
--
--END--
--
--BEGIN ut_dm_maps.htm --
--
"dm-007archives","DM-007Archives",720,"dm-007archives",7.5
"dm-007caves","DM-007Caves",349,"dm-007caves",7.5
[snip]
etc etc
any lines ending in -1 mean that map is unrated.
I'd like to expand this script (and fix it) so that it does three things
#1. parses maps_list.txt and counts the # of rated maps vs unrated maps
and spits out a percentage for each.
#2. scans my Maps folder for the files I have, finds the line in
maps_list.txt that containes the same name (probably have to convert
both to lowercase), and tells me if it's rated or not.
#3. I'm also interested to learn how to parse a comma delimited listing
-- I'm thinking that Uri's tutorial will help there, but I still need to
know how to break up the items as each line is read in, into their
separate variables, and I don't know how to do that yet.
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Wed, 10 May 2000 16:09:55 +0200
From: Matthias Kleine - Patzschke + Rasp Software AG <Matthias.Kleine@prs.de>
Subject: conversion hex->ascii, ascii->mif, oder hex->mif
Message-Id: <39196DB3.E6BE3F17@prs.de>
Hallo Liste!
Da gab es doch eine Funktion, die hexadezimal dargestellte Zeichen
in Plain umwandelt... Besser noch - weiss jemand, ob es ein Modul
fuer die Bearbeitung von mif - Dokumenten (Maker Interchange Format)
gibt? Auf CPAN gab es zwar angeblich ein Framemaker-Modul, doch leider
blieb der Link kalt...
Vielen Dank fuer Hinweise.
Matthias
------------------------------
Date: Wed, 10 May 2000 16:10:45 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: File Upload Script
Message-Id: <Pine.GHP.4.21.0005101546550.8113-100000@hpplus03.cern.ch>
On Wed, 10 May 2000, Joydip Chakladar wrote:
> Try this
Always a warning sign on usenet. I haven't fully audited this script,
but it seems to fully confirm my deep suspicion of all recipes that
are offered on "try this" basis.
CGI scripts are a serious matter, they can compromise the health of
your whole server. I'd advise people to understand what they are
doing, rather than picking up arbitrary lumps of cut'n''paste "try
this" code.
> $fileName =~ s!^.*(\\|\/)!!;
Surely on Macs the file path separator is a colon, isn't it? I'd also
have reservations about things like spaces and semicolons in the
filename...
> if ($filenotgood ne "yes") {
Double negatives are a popular source of confusion...
Also, we see no evidence you paid the slightest attention to the
already-posted advice about binmode().
> open (OUTFILE, ">$basedir/$fileName");
No test for a successful open.
> close (OUTFILE);
No test for a successful close.
> print "Location: $donepage\n\n";
If that's meant to be an HTTP redirection, then I'd have to advise you
that a redirection response to a POST transaction can be quite
problematical. But since you haven't shown which of the two kinds of
Location response you're trying to produce (the fully-specified URL or
the URLpath), it's hard to be sure.
Scorefile adjusted.
------------------------------
Date: Wed, 10 May 2000 07:50:41 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: File Upload Script
Message-Id: <39197741.D87FC2AC@vpservices.com>
"Alan J. Flavell" wrote:
>
> > if ($filenotgood ne "yes") {
>
> Double negatives are a popular source of confusion...
But that's a double (or perphas triple) positive too so it all balances
out :-)
not good not equal yes
--
Jeff
------------------------------
Date: Wed, 10 May 2000 16:13:30 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Gotta be in the FAQ...but it doesn't seem to be...
Message-Id: <Pine.GHP.4.21.0005101612490.8113-100000@hpplus03.cern.ch>
On Tue, 9 May 2000, Jeff Zucker wrote:
> The problem is that there are some servers (notably apache) that work on
> NT and require a shebang, ignoring the file association completely.
I perceive that as a benefit rather than a problem!
;-)
------------------------------
Date: Wed, 10 May 2000 07:44:33 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Gotta be in the FAQ...but it doesn't seem to be...
Message-Id: <391975D1.B42BD1D3@vpservices.com>
"Alan J. Flavell" wrote:
>
> On Tue, 9 May 2000, Jeff Zucker wrote:
>
> > The problem is that there are some servers (notably apache) that work on
> > NT and require a shebang, ignoring the file association completely.
>
> I perceive that as a benefit rather than a problem!
>
> ;-)
Definitely! :-) My use of the word "problem" was in relation to the
posting that asked "What's the problem with just using file
associations?"
--
Jeff
------------------------------
Date: Wed, 10 May 2000 06:04:48 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: How to parse CGI input with perl 5.003 (was Re: How can I call a perl script from html-page)
Message-Id: <39195E70.96F9F788@vpservices.com>
[courtesy cc sent to Saddek Rehal]
Saddek Rehal wrote:
>
> Thank you very much for helping me.
> For the moment I have Perl ver 5.003 without cgi.pm. This require Perl 5.004.
> I wonder if there is an other way for me to solve the problem without using
> cgi.pm.
Well everything I wrote about how a URL and a form send variables to a
CGI script works regardless of how you parse the input within the CGI.
My best advice is to try to get the Perl version upgraded. Telling
whomever administers the server that all versions of Perl before 5.004
have known security holes and published bugs and are open to misuse may
motivate them to make a change (this is all well documented so it is not
an exaggerated claim).
If you can't get the Perl version upgraded, I am not sure what your
options are, probably to use a *modified* version of the cgi-lib.pl
routines. Other newsgroup members -- any suggestions?
--
Jeff
------------------------------
Date: Wed, 10 May 2000 13:33:26 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: how to use fork or background processing (in Perl/Tk)?
Message-Id: <GydS4.67972$h01.486188@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8fbiqj$fbi$1@porthos.nl.uu.net>,
"Michael Schlueter" <michael.schlueter@philips.com> writes:
> If I'd use fork like is given in "Programming Perl", are there any traps and
> pitfalls I could tap into? I intend to use fork/background_jobs with
> Perl/Tk.
You COULD use fork, but probably don't need to here.
> * when starting up a GUI the user usually has to spend some time anyway. I'd
> like to scan and prepare larger datafiles in background in parallel. the
> user should notice 'improved speed' from this.
>
> * some calculations will take quite some time. once finished the user should
> be informed or the GUI should update automatically. how to do that?
Both of these could be handled by having in the middle of your calculation
loop a Tk idletasks call. This would allow Tk to catch up on screen display
stuff, process some callbacks, etc... but your application would still be
reading/processing. It makes for a less complicated program.
> Do I need to care about Signal-processing (Ch. 6 of PP)? Are there
> alternatives?
Signal handling is bad, avoid it whenever possible. It's unreliable in
Perl and probably always will be.
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 10 May 2000 15:59:26 +0200
From: "Michael Schlueter" <michael.schlueter@philips.com>
Subject: Re: how to use fork or background processing (in Perl/Tk)?
Message-Id: <8fbpso$kko$1@porthos.nl.uu.net>
Hi Clinton,
Thank you for your hint. I am happy to hear your oppinion.
>
> Both of these could be handled by having in the middle of your calculation
> loop a Tk idletasks call. This would allow Tk to catch up on screen
display
> stuff, process some callbacks, etc... but your application would still be
> reading/processing. It makes for a less complicated program.
>
>
It is quite some time ago that I worked with Perl/Tk and the Perl/Tk Pocket
Reference is somewhat short here. Do you mean something like:
my $mw = MainWindow->new();
my $cv = Canvas( options ) ->pack();
...
$cv->idletasks(); # or from other widgets derived from $mw or $cv
...
?
If I'd store my data in @data and I'd have something like:
my @data;
my $mw = MainWindow->new();
my $cv = Canvas( options ) ->pack();
...
$cv->idletasks(); # or from other widgets derived from $mw or $cv
get_data(/@data); # meant as a background process
display($cv, \@data); # puts actual set on the canvas
...
would this automatically update a change in @data on the canvas?
Thanks again,
Michael
------------------------------
Date: Wed, 10 May 2000 14:06:35 GMT
From: scarey_man@my-deja.com
Subject: Re: Inserting text in a chart
Message-Id: <8fbqcv$2hl$1@nnrp1.deja.com>
In article <8fbcpg$jp5$1@nnrp1.deja.com>,
scarey_man@my-deja.com wrote:
> How do I add text to a chart using the GD::Graph modules?
> I want to be able to add text to any coords I specify.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
I found the answer myself.
my $gd=$my_graph->gd();
my $align = GD::Text::Align->new($gd,
valign => 'top',
halign => 'right',
);
$align->set_font('/usr/fonts/verdana.ttf', 9);
$align->set_text('Please work');
$align->draw(200,200,45);
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 10 May 2000 08:13:15 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Is Perl fast enough?
Message-Id: <slrn8hikir.i9i.tadmc@magna.metronet.com>
On Wed, 10 May 2000 02:20:31 GMT, pohanl@my-deja.com <pohanl@my-deja.com> wrote:
>Whas is XS module?
perldoc -q XS
[ snip Jeopardy quoting of entire damn article ]
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 10 May 2000 15:02:41 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: Is Perl fast enough?
Message-Id: <8fbtmh$j2h$1@216.155.32.13>
In article <MPG.1382057d220926d098aa35@nntp.hpl.hp.com>, Larry Rosler
<lr@hpl.hp.com> wrote:
| In article <brian-ya02408000R0905001442050001@news.panix.com> on Tue, 09
| May 2000 14:42:05 -0400, brian d foy <brian@smithrenaud.com> says...
| > In article <8f9jlc$2s0$1@plutonium.btinternet.com>, "Andy Chantrill"
| > <andy@u2me3.com> posted:
| >
| > > I'm developing an application in my spare time that plays around
| > > with ~15
| > > million lines in half a dozen different files, and then plays with a
| > > mySQL
| > > database. I have a system that works, but it's extremely memory
| > > intensive -
| > > causing a stack overflow when I run it on the live files :o(
| >
| > use less memory :)
|
| ITYM 'buy more memory' :-)
require More::Memory::Installed; # ;D
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Wed, 10 May 2000 13:54:31 GMT
From: mfelps@my-deja.com
Subject: Problem processing multiple files
Message-Id: <8fbpme$1sc$1@nnrp1.deja.com>
First the script:
$dirname="test";
opendir(DIR, $dirname) or die "can't opendir $dirname: $!";
while (defined($file = readdir(DIR))) {
open (FILE, $file); #open original html file
$file2="new".$file; #prepend new to file name
open (FILE2, ">$file2"); #open new file for writing
while ($line=<FILE>){ #read in the file
#replace </BODY>with (link) <BODY>
$line=~
s/<\/[Bb][Oo][Dd][Yy]>/<BR><AHREF=http:\/\/www.foobar.com>Link\n<\/BODY>
/;
print FILE2 $line; #write line to new file
}
close (FILE); #close files
close (FILE2);
}
closedir(DIR); #close directory
Okay, basically this is supposed to open each HTML file in the
"test" directory and then print out a new page
(from test1.html to newtest1.html) and the new page should have a link
at the end of the page.
It works if I use it against a single file (ie: leaving off the 1st
three lines [and the last]). It sort of works this way,
in that it opens the files for write, but it never writes anything to
them. I get a bunch of blank newtest.html files. I did the middle
part, and swiped the multiple file processing code from Perl Cookbook.
Any ideas why this only half works?
Mark Felps
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 10 May 2000 14:47:03 GMT
From: The WebDragon <nospam@devnull.com>
Subject: Re: Proper use of resources (was Re: more regexp madness extracting data from files.)
Message-Id: <8fbsp7$j2h$0@216.155.32.13>
In article <8fatkj$hu6$1@orpheus.gellyfish.com>, Jonathan Stowe
<gellyfish@gellyfish.com> wrote:
| > I'd like to add to this script the ability to grab these six .html
| > files containing the data I wish to extract via http, and save
| > them locally, overwriting the previous ones, before running this
| > script on them and generating my output file of the data. (this
| > way I can daily keep my local output file up to date.)
| >
| > Which modules do you recommend that would best suit this sort of
| > thing? I'm guessing one of the Net:: or HTTP:: modules? Which wuld
| > you use? and why?
|
| LWP::Simple or LWP::UserAgent depending on your requirements and the
| degree of control you want over the process. Why ? Because they are
| the only modules that do this sort of thing. the HTTP::* modules are
| part of the same distribution and provide the framework for LWP to get
| things with an http: protocol scheme. The module suite comes with a
| a very good document of examples 'lwpcook.pod' that should get you
| started.
here's the final script: fileGrab2.pl
#!perl -w
use strict;
use diagnostics -verbose;
use LWP::UserAgent;
use File::Spec;
my $inputDir = File::Spec->catfile( File::Spec->curdir(), 'input_files',
'');
my $baseURL = "http://www.planetunreal.com/nalicity/";
#fixed fileslist
#my @filesList = qw(
# ut_assault_maps.htm
# ut_capturetheflag_maps.htm
# ut_dm_maps.htm
# ut_dm_maps_b.htm
# ut_domination_maps.htm
# ut_other_maps.htm
#);
#active fileslist
opendir(DIR, $inputDir) || die ("Cannot opendir $inputDir : $!");
my @filesList = readdir(DIR);
closedir DIR;
for (@filesList) {
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request 'GET' => $baseURL . $_;
my $response = $ua->request($request);
die "$baseURL $_ failed: ",$response->error_as_HTML
unless $response->is_success;
open(OUT, ">$inputDir$_") or die ('Aieeeeee');
print OUT $response->content;
close OUT;
};
my @dataList;
for (@filesList) {
my $grabFile = $inputDir . $_;
open(GRAB, "<$grabFile") or die ("Cannot open file $grabFile : $!");
# print "Successful open of $grabFile\n";
push @dataList, "-- $_\n";
while(<GRAB>) {
tr/\r//d;
next unless /^\Qmaps[i++] = new Map(\E([^)]+)/;
push @dataList, "$1\n" ;
# print "$1\n";
}
close (GRAB);
};
open(OUT, ">maps_list.txt") or die ("DOH! can't create the maps list :
$!");
# for (@dataList) { print OUT "$_\n" }
print OUT @dataList;
close (OUT);
__END__
I changed a few things, and set it up so each section is simply prefaced
by
-- filename
this should make parsing the list a bit easier in the future.
any comments? comments are good :)
--
send mail to mactech (at) webdragon (dot) net instead of the above address.
this is to prevent spamming. e-mail reply-to's have been altered
to prevent scan software from extracting my address for the purpose
of spamming me, which I hate with a passion bordering on obsession.
------------------------------
Date: Wed, 10 May 2000 13:04:56 GMT
From: vlad55@my-deja.com
Subject: Re: Pulling my hair out!
Message-Id: <8fbmpd$ueu$1@nnrp1.deja.com>
In article <957176011.20224.0.nnrp-13.d4e441b4@news.demon.co.uk>,
"Adam T Walton" <waltonic@earbuzz.demon.co.uk> wrote:
> Please help... this is the first time I have come across regular
expressions
> and I can't seem to get them to do what I want them to! I can get
them to
> work fine for boolean matches and testing, but when I try and extract
the
> matches the whole thing goes a bit pear-shaped!
>
> All I want to do is extract double-quoted strings from an input
string that
> might contain a mixture of double quoted, and non-quoted strings...
>
> eg.
>
> "murry the hump" big leaves "terris" catatonia "60ft dolls"
>
> a regexp that would extract "murry the hump", "terris" and "60ft
dolls" and
> stick them into an array.
> I have been trying variations of:-
>
> @chopped=/"([^"]+)"/g;
try this:
@chopped=/"([^"]+?)"/gcs;
not sure but may help
>
> This works but totally ignores the first double-quoted string (ie. in
the
> above example @chopped would contain "terris" and "60ft dolls", but
NOT
> "murry the hump"!!!!)... why why why why????
>
> I am almost certain that this is the Perl equivalent of taking your
computer
> to a repairman, only to be told that you need to plug it in and
switch it on
> for it to work... but, sometimes, the answer that is staring you in
the face
> is the hardest one to see!
>
> Thanks in advance to anyone who has the inclination to help me
>
> It will be MUCH appreciated :)
>
> Adam
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 10 May 2000 10:16:09 -0400
From: Scott Chapal <schapal@mail.jonesctr.org>
Subject: Recursive copy (Skip links)
Message-Id: <psnvqsd7a.fsf@mail.jonesctr.org>
What is a GOOD way in perl to do a recursive copy of a directory,
preserve file attributes, replicate link names, but avoid copying from
links?
For example this directory can cause trouble using cp -rp, tar etc.
bash-2.03$ pwd
/home/schapal/.gnome-desktop
bash-2.03$ ll
total 16
lrwxrwxrwx 1 schapal users 11 May 5 11:26 fd0 -> /mnt/floppy
lrwxrwxrwx 1 schapal users 8 May 5 11:26 hda2 -> /mnt/fat
lrwxrwxrwx 1 schapal users 13 May 5 11:26 Home directory -> /home/schapal/
-rw-r--r-- 1 schapal users 27 Feb 4 12:14 RH.com
-rw-r--r-- 1 schapal users 38 Feb 4 12:14 RHerrata
-rw-r--r-- 1 schapal users 27 Feb 4 12:14 RHgnome
-rw-r--r-- 1 schapal users 39 Feb 4 12:14 RHldp
-rw-r--r-- 1 schapal users 32 Feb 4 12:14 RHsupport
File::Find and File::Copy ??
--
\SEC
------------------------------
Date: Wed, 10 May 2000 08:37:36 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: sort a two-dimensional array....
Message-Id: <39196620.E185C0B4@home.com>
Thomas Wolfensberger wrote:
>
> I need to sorrt a two-dimensional array.
> How can i do it?
The answers you seek are as close as your keyboard. Type
'perldoc -q sort' at your command prompt.
perlfaq4: "How do I sort an array (by anything)"
Just a note: Good nettiquette requires checking the FAQ and docs before
posting here. You'll get quicker (and likely better) information, and
won't p*ss off the natives.
-mjc
------------------------------
Date: Wed, 10 May 2000 13:08:37 GMT
From: Ilja <billy@arnis-bsl.com>
Subject: Re: URGENT HELP WITH REGEXP REQUIRED
Message-Id: <8fbn08$uve$1@nnrp1.deja.com>
In article <8fbjgc$r1e$1@nnrp1.deja.com>,
vlad55@my-deja.com wrote:
> I have a question,
>
> I am trying to replace a text containing different chars by another
> text block, problem is
> my $newhtml =~ s/<!--[\n\t\r\ ]+VMySQLQueryParser$oldfunc\-->$old<!--
> [\n\t\r\ ]+END[\n\t\r\ ]+-->/<!-- VMySQLQueryP ... .../gs;
>
> treats the $oldfunc as a search pattern instead of static text, so if
> the $func (or $old) contains chars like [,],(,),* etc.. it tries to
> match them...
>
> is there a quick workaround this?
>
\Q$oldfunc\E
See your local 'perldoc perlre' or
http://www.cpan.org/doc/manual/html/pod/perlre.html for details.
Ilja.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 10 May 2000 09:50:05 -0400
From: "Ron Grabowski" <ronnie@catlover.com>
Subject: Re: using Perl's RE to do basic manipulation of a flex file
Message-Id: <8fbpcn$org$1@news.cis.ohio-state.edu>
>I understood that. The problem that I have, and the reason why I didn't
>reply before, is with the //s modifier. Apparently you want to allow
>multiline code blocks. That implies that you cannot process this data
>one line at a time? Ooh...
That is correct. In my original post I said:
The information between the brackets that
contain the 'return' does not have to be on one-line:
{ANOTHER_TOKEN}[0-9]
blah();
return TOKEN2 ;
}
is valid too.
>If you DO process one line at a time, try matching the last "{" instead
Processing one line at a time is not an option because many of the blocks
span multiple lines.
What I'm trying to do doesn't seem all that difficult. I have a beginning
pattern and an ending pattern and I want to match everything inside of those
two.
- Ron
------------------------------
Date: Wed, 10 May 2000 13:28:48 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Win32 SYSTEM window
Message-Id: <kudS4.67958$h01.486188@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <391966e7.0@news2.cluster1.telinco.net>,
"Stuart" <stuart.tavener@greenwichnatwest.com> writes:
> Is there anyway of running a perl script or exe, as a quiet process in the
> background, so i dont get that annoying black ms-dos system window appearing
A GREAT place to start getting answers to Win32 questions like this is
www.activestate.com. Check both their Win32FAQ and the mailing list archives.
(You'll find your answer there. It depends on what you want to do.)
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 10 May 2000 13:36:12 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: windos equivalent of fork ???
Message-Id: <gBdS4.67980$h01.486188@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <8fatsl$3gn$1@nnrp1.deja.com>,
itsaw@my-deja.com writes:
> is there a fork for windows in perl ??? I am trying to create child
> process under windows , i know i can do it under linux using fork but i
> am not sure is there for windows .......can anyone help me with this
> problem .... thanks in advance
You didn't research this very much, did you? Perl 5.6 contains fork()
for Windows 32. It's covered in the perlfunc, perlfork, and perldelta
manual pages. It's also been prominently featured in every announcement
for Perl 5.6 for the last two months.
Good luck!
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours!
clintp@geeksalad.org for details see http://www.geeksalad.org
"If you rush a Miracle Man,
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3003
**************************************