[12840] in Perl-Users-Digest
Perl-Users Digest, Issue: 250 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 25 08:10:24 1999
Date: Sun, 25 Jul 1999 05:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sun, 25 Jul 1999 Volume: 9 Number: 250
Today's topics:
Re: Best Perl book? <unigni@zaynar.demon.co.uk>
Re: Best Perl book? (Anno Siegel)
Re: command line input (Anno Siegel)
flock - does it wait for people to finish reading? <jamesthurley@hotmail.com>
Re: Globs and such (Anno Siegel)
Re: its 1.30am <snip> - eval - morning - I can see clea (Eric Smith)
Re: output to screen and log file simultaneously? (Mike Bristow)
Re: Perl 4 Source Code or Binaries <gellyfish@gellyfish.com>
Re: Perl in webpages (Anno Siegel)
pgp sign mail (Tony Greenwood)
Re: problem for autoforwarding (Anno Siegel)
Professional Perl Programmer required. <kbrelis@home.com>
Re: program runtime problem.. (Anno Siegel)
Re: program runtime problem.. (Mike Bristow)
Re: Regex Problem - I think (r j huntington)
Replacing and Stripping HTML (Anno Siegel)
Re: special problem <perly@ufl.edu>
Re: template (Anno Siegel)
Re: Waiting for system ?? <info@servicepool.de>
Re: Waiting for system ?? (Anno Siegel)
Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 25 Jul 1999 10:27:42 +0100
From: Unigni <unigni@zaynar.demon.co.uk>
Subject: Re: Best Perl book?
Message-Id: <QPhqZAAOitm3EwHb@zaynar.demon.co.uk>
In article <slrn7ple5q.ap5.dha@panix7.panix.com>, "David H. Adler"
<dha@panix7.panix.com> writes
>In article <7ndbdj$r9v$1@plonk.apk.net>, Jody Fedor wrote:
>>
>>Unigni wrote in message ...
>>>I have a little programming experience, and want to start learning Perl,
>>>probably for CGI use on the Web... Can anybody suggest what would be the
>>>best book(s) to get?
>>
>>
>>I use mostly O'Reilly books:
>>
>>Programming Perl (Camel Book) - Wall, Christiansen & Schwartz
>>Perl Cookbook (Ram Book) - Christiansen & Torkington
>>Learning Perl (Llama Book) - Schwartz & Christiansen
>>Mastering Regular Expressions (Owl Book) - Friedl
>>Advanced Perl Programming (Panther Book) - Srinivasan
>
>O'Reilly certainly is the best source for perl info in book form.
>Larry Wall, the creator of perl, is employed by them to, as I
>understand it, be, well, Larry. :-)
>
>3 additional points:
>
>A) If you will be using perl on a Windows system, you might keep in
> mind that Learning Perl (mentioned above) also comes in a version
> for Win32 systems.
>
>2) One book not by O'Reilly comes to mind as a good bet - Effective
> Perl Programming by Hall and Schwartz, published by
> Addison-Wesley.
>
>iii) A listing of perl books with ratings is available at the perl home
> page: http://www.perl.com/pub/language/critiques/index.html
Wouldn't that site be a little bit biased towards O'Reilly books, since
they actually own the web site? :-)
--
Philip Taylor
philip @ zaynar . demon . co . uk
http://www.ultrastore.com -- "The Shopping Experience of Tomorrow - NOW!"
(an example of what can be done with *loads* of JavaScript and cookies!)
------------------------------
Date: 25 Jul 1999 09:37:35 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Best Perl book?
Message-Id: <7nelsv$5a0$1@lublin.zrz.tu-berlin.de>
Unigni <unigni@zaynar.demon.co.uk> quoted 30+ lines to comment:
>>iii) A listing of perl books with ratings is available at the perl home
>> page: http://www.perl.com/pub/language/critiques/index.html
>Wouldn't that site be a little bit biased towards O'Reilly books, since
>they actually own the web site? :-)
Please trim your quotes if you're only replying to part of an article.
Thanks.
Anno
------------------------------
Date: 25 Jul 1999 09:43:40 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: command line input
Message-Id: <7nem8c$5b6$1@lublin.zrz.tu-berlin.de>
Bob Walton <bwalton@rochester.rr.com> wrote in comp.lang.perl.misc:
>Ed Doyle wrote:
...
>Ed, the arguments will appear in array @ARGV in the MAIN package of your Perl
^^^^
main
>program. See perlvar for documentation. Here is one way you can print them:
>
>print "$_\n" for @ARGV;
Anno
------------------------------
Date: Sun, 25 Jul 1999 12:47:54 +0100
From: "James Thurley" <jamesthurley@hotmail.com>
Subject: flock - does it wait for people to finish reading?
Message-Id: <7netgf$1gs$1@gxsn.com>
This may seem a stupid question, but when you lock a file with flock(), does
it wait for people to finish reading from the file before it locks it (if
the people reading it haven't locked it)?
Thanks,
James.
------------------------------
Date: 25 Jul 1999 09:11:48 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Globs and such
Message-Id: <7nekck$57g$1@lublin.zrz.tu-berlin.de>
RPJOSE82 <rpjose82@aol.com> wrote in comp.lang.perl.misc:
>I am reading the "Camel" book, and it is talking about references and globs.
>Although it seems to give a pretty good explanation, I still find myself
>confused. Could anyone help me with what exactly these are and how they are
>used? Thanks!
It would be presumptuous to try to beat the Camel in comprehensiveness
and clarity in an offhand usenet article. You also have on your hard
disk the perl docs, in particular perlref. The perl faq may also have
to say a thing or two about the subject (available via perldoc -q).
If these, and cheerful experimentation to see how things work don't help
you understand the issues, the most knowledgeable and didactically
adroit contributers to this group (there are a few) would be hard
pressed to do better.
Your question is way to general. Come back when you have a specific
question, like a bit of code that doesn't do what you think it
should do.
Anno
------------------------------
Date: 25 Jul 1999 11:16:48 GMT
From: eric@fruitcom.com (Eric Smith)
Subject: Re: its 1.30am <snip> - eval - morning - I can see clearly now ...
Message-Id: <slrn7plshg.ho9.eric@plum.fruitcom.com>
brian@pm.org (brian d foy):
>
> what are you trying to do? that is, what behaviour are you trying
> to get? if you are trying to match against something in $_, then
> you need something in $_ for it to succeed. what's supposed to be
> in @ARGV?
Thanx Brian
Ok, I have this script that looks in my flat text telephone list (it a
largish list). Now it used to take only three args and the script needed
to match those three args in the same line, so ..
bri Fo mong
as args, would match an entry
Perl Mongers, Brian Foy
Now I wanted to be able to use unlimited number of args for this script so
thats what I failed to do last night, being the first time I had the
courage to use eval. Well this morning it works :).
Albeit a little slowly, anyone know how to make it faster .. see code
below.
Now the next step is to create a facility where the user can supply on the
command line a number of sets of args thusly
bri Fo mong, eri accid smi hacker
and this would give Brian Foy _and_
Eric Smith - Accidental Hacker
I am thinking of an array of arrays to do this.
BTW I must get some of that perl monger clothing off your page for our
Cape Town Mongers.
ciao
===========================================================
#!/usr/bin/perl -w
print "@ARGV \n";
$command .= "print if ";
for $i (0..$#ARGV){
if ($i == $#ARGV) {$command .= "/$ARGV[$i]/i\;"} else
{$command .= "/$ARGV[$i]/i and "}
}
print "Here is the \$command: \n";
print $command;
print "\n";
print "Here is the eval of the \$command: \n";
open FILE, "yourfilehere";
while (<FILE>) {
eval $command;
}
print "\n";
close FILE;
===========================================================
>
> --
> brian d foy
> CGI Meta FAQ <URL:http://www.smithrenaud.com/public/CGI_MetaFAQ.html>
> Perl Monger Hats! <URL:http://www.pm.org/clothing.shtml>
------------------------------
Date: Sun, 25 Jul 1999 11:25:17 GMT
From: mike@fat.dotat.at (Mike Bristow)
Subject: Re: output to screen and log file simultaneously?
Message-Id: <slrn7plt0t.983.mike@lindt.fat.dotat.at>
On 25 Jul 1999 07:44:31 GMT, GEMINI <dennis@info4.csie.nctu.edu.tw> wrote:
>I use print,warn, and die to output message to
>screen in my program. I wish to save these message (including that
>generated by warn and die)
>to a log file at the same time. Is there any way to do so
>by not changing the structure of program. Don't suggest me to
>use a subroutine that print to stdout, and print to file, then call
>subroutine to output message.
>thanks.
sh -c 'yourscript 2>&1 | tee logfile'
(this is not perl specific ;-)
--
Mike Bristow, Geek-At-Large. GK/RM0501
one tequila - two tequila - three tequila - FLOOR !!!
------------------------------
Date: 24 Jul 1999 18:20:06 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Perl 4 Source Code or Binaries
Message-Id: <7nd04m$1e9$1@gellyfish.btinternet.com>
On Fri, 23 Jul 1999 18:46:37 +0200 Dr. Who wrote:
> hmm ..in sweden Anno is a female name ..
> - are you? :)
>
In England Dr Who is a Galifrean with two hearts - are you ...
/J\
--
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
------------------------------
Date: 25 Jul 1999 11:54:32 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl in webpages
Message-Id: <7netto$5l4$1@lublin.zrz.tu-berlin.de>
Kevin Pickens <webmaster@source.findhere.com> wrote in comp.lang.perl.misc:
>I have a webpage that is generated by a perl script
>(http://start.cgirealm.com/foundandlost/button.pl). The output from the
>script is a full bore html document including a content header.
>It includes an HTTP-EQUIV refresh going to the same script.
>
>The problem comes when the script is activated by anything other than
>the location bar (i.e. from a frameset -
>http://members.xoom.com/thesourcerpg/ads.htm left side frame, or when it
>refreshes). In that case, I get a message box saying:
> You have started to download a file of type
> application/x-perl
>from Netscape.
>Is there any way to get it to work properly (i.e. refresh or load in the
>frame without the download message)?
Just because the html is created by a Perl script doesn't mean it's
a Perl problem. Ask a newsgroup with perl or cgi in it's name.
Anno
------------------------------
Date: Sun, 25 Jul 1999 11:34:02 GMT
From: tony@webscripts.org (Tony Greenwood)
Subject: pgp sign mail
Message-Id: <37a8f488.9159879@news.freeserve.co.uk>
I am able to post an email encrypted using the following
open (PGP, "|$pgpprog -feat +VERBOSE=0 \"mykeyname\" > $pgptmp");
The above works perfectly.
Now I wish to sign rather than encrypt and from what I can find the
following should work as -sta -u signs.
open (PGP, "|$pgpprog -sta -u \"mykeyname\" > $pgptmp");
However the above produces a blank email. Because everything works
with encrypt then we know all the paths are set right and the key is
valid..can anyone throw any light onto what I should do to sign rather
than encrypt.
Any help appreciated:)
--
Tony Greenwood
PORTFOLIO www.webscripts.org
------------------------------
Date: 25 Jul 1999 09:21:34 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: problem for autoforwarding
Message-Id: <7nekuu$58o$1@lublin.zrz.tu-berlin.de>
kenny <kenny@autoemail.net> wrote in comp.lang.perl.misc:
>Hi everyone:
>How can i autoforward an email with perl?
Can I use a chainsaw to cut bread? You can, if you have to. If you
are on a unix system, you don't have to. Get someone to explain what
the .forward file does. If you're on dos or win*, I don't know.
>can i get the RCPT TO: from the envelope ? because RCPT TO is the real
>recipent.
If your mailer doesn't give you the envelope headers, you'll have to
go through some contortions, like setting up a sendmail proxy. You
can do that in perl, but the question has nothing to do with perl.
Anno
------------------------------
Date: Sun, 25 Jul 1999 08:29:49 GMT
From: "Kevin Brelis" <kbrelis@home.com>
Subject: Professional Perl Programmer required.
Message-Id: <1Wzm3.15664$_9.214182@news1.rdc1.ab.home.com>
I am looking for an experienced and efficient Perl Programmer to assist me
with a large oilfield web project I am currently consulting on. Web site
launch date is January 2, 2000. If your interested please visit the url
below for more details. Thank you,
http://www.devansoft.moreprofits.com/cmhl/script.htm
------------------------------
Date: 25 Jul 1999 08:10:40 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: program runtime problem..
Message-Id: <7negq0$54v$1@lublin.zrz.tu-berlin.de>
cho man fai <mfcho7@ie.cuhk.edu.hk> wrote in comp.lang.perl.misc:
>Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>: cho man fai <mfcho7@ie.cuhk.edu.hk> wrote in comp.lang.perl.misc:
>: >Dear all,
>: >
>: >I recently write a program to tail -f the sendmail log file. I assume
>: >the program can be started and run forever to find out any spammer if
>: >they send emails with a number of mails within a period of time. The
>: >program, however, works only for around the first day only but not
>: >afterwards.
>
>: I doubt that's a good way to detect spammers. They're very good
>: at "elegant variation" of their purported From-addresses. But
>: that's beside the point.
>
>This is not the best way but a way to detect spamming automatically. The
>script check with emails in a sender as well as relay basis. Thus, if
>the sender use a variable sender email address, I may still detect it by
>their relay.. You are right however that it is not a perfect way to
>stop spamming, but this is all I think we can do at this moment. Do
>others have some good idea in tackling spams? Please kindly share with
>us.. :)
You'd best ask an experienced postmaster (mail admin) about that.
I'm sure there is a newsgroup for those. Come to think of it,
spam being the pest it is, there is almost certainly also a newsgroup
specialized in spam prevention. Myself, I'm behind a spam filter
set up on the mail server. I don't know how much it blocks, but I
can live with the two or three a day that slip through.
>: >I suspect it is owing to the associative arrays growing and excced the
>: >limit (memory? or what?) to hold the sender and relay address. Is there
>: >any limit for that in perl? The array grows in the program and it is
>: >unavoidable. I did try to clear the array periodically, say every hour,
>: >but failed. May you tell me the way to clear the assiciative array or
>: >any workarounds you may think of?
>
>: Generally speaking, you'd undef %assoc_array. Since you don't show
>: any code it's hard to say if that would free the memory or not.
[snip]
>Then, let me try to undef the associative array. Will the memory be free
>up after I undef the array, say everyday or every 12 hours?
As I said, it's hard to say without seeing the actual code. But if
you don't have references in your program it's pretty safe to say
that it will be freed.
Don't let the fact fool you that the program size doesn't seem to get
smaller when you undef the hash. Many operating systems never let a
process shrink, but perl will be able to re-use the space you have
freed, so the program will not grow much more after the first few
days.
Anno
------------------------------
Date: Sun, 25 Jul 1999 11:52:57 GMT
From: mike@fat.dotat.at (Mike Bristow)
Subject: Re: program runtime problem..
Message-Id: <slrn7pluko.983.mike@lindt.fat.dotat.at>
On 24 Jul 1999 17:33:29 GMT, cho man fai <mfcho7@ie.cuhk.edu.hk> wrote:
>Dear all,
>
>I recently write a program to tail -f the sendmail log file. I assume
>the program can be started and run forever to find out any spammer if
>they send emails with a number of mails within a period of time. The
>program, however, works only for around the first day only but not
>afterwards.
>
>I suspect it is owing to the associative arrays growing and excced the
>limit (memory? or what?) to hold the sender and relay address.
I suspect logfile rotation, instead.
Is the program still running, just no longer doing what you expect?
If it is, then see if the breakage occurs at the same time as the
daily logfile rotation - this will be a very strong hint IMO.
Logrotation is done by newsyslog on both FreeBSD and IIRC SunOS; I
think the deadrat equivilent would be logrotate or something: ask
$GURUS{$^O} to be sure.
The way to deal with this would be:
When you first open the file, stat the filehandle
and remember the inode from the result.
In the main loop, stat the filename and store
the inode again.
After you've sucked up the available lines, compare the
inode you last got from the filehandle and the inode
you last got from the filename: if they differ, reopen the
file. If they don't, clear the EOF condition, and sleep abit.
Taking the example in perlfaq5 (``How do I do a C<tail -f> in perl''),
and modifying it a bit, I get:
--- example, untested, code ---
open GWFILE, "$filetotail" or die "Eeek: $!";
my $inodefh = (stat GWFILE)[1];
for (;;) {
my $inodefn = (stat $filetotail)[1];
for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) {
# search for some stuff and put it into files
}
if ($inodefh != $inodefn) {
close GWFILE;
open GWFILE, "$filetotail" or die "Eeek: $!";
$inodefh = (stat GWFILE)[1];
} else {
# sleep for a while
seek(GWFILE, $curpos, 0); # seek to where we had been
}
}
--- exanple, untested, code ---
It has the following problems: I'll leave it to you to deal with them
(hopefully I've given you enough of an idea to get going)
a) It's untested & may not work
b) It assumes that the stat operator returns a meaningfull inode
c) Theres a race condition: if the new file isn't created
before it tries to reopen it, the script'll die.
d) Assorted others I can't think of right now ;-)
--
Mike Bristow, Geek-At-Large. GK/RM0501
one tequila - two tequila - three tequila - FLOOR !!!
------------------------------
Date: 25 Jul 1999 10:34:58 GMT
From: wolph@merlin.albany.net (r j huntington)
Subject: Re: Regex Problem - I think
Message-Id: <7nep8i$mik$1@news.monmouth.com>
Anno Siegel (anno4000@lublin.zrz.tu-berlin.de) wrote:
: r j huntington <wolph@merlin.albany.net> wrote in comp.lang.perl.misc:
: >Jordan Hiller (hiller@email.com) wrote:
:
: >: $string =~ s#/.*##;
: >
: >Hi, thanks, Jordan, but I get:
: >
: >"Can't modify division in scalar assignment..."
:
: You're getting *what*? Not with Jordan's substitution. It works
: just fine. Just try it the way it is.
I did, but I had a typo. Indeed, it does work. Thank you both.
I am learning. Thank you. NOW, it seems so obvious what this
substitution should be. Sure didn't before. Maybe that's a
good sign. ;-)
Thanks again to Jordan and Anno. - Ralph
------------------------------
Date: 25 Jul 1999 11:47:34 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Replacing and Stripping HTML
Message-Id: <7netgm$5jq$1@lublin.zrz.tu-berlin.de>
Faisal Nasim <swiftkid@bigfoot.com> wrote in comp.lang.perl.misc:
>: Here is what I am trying to do:
>:
>: 1. Open a file (which I know how to do)
>
>nice!
>
>: 2. Replace every occurance of </FONT> in that file with |
>
>see, s///
>
>: 3. Strip remaining HTML from the file
>
>look at HTML::Parser
Will HTML::Parser be happy after the </FONT> thingies (are those tags?)
have been replaced?
>: 4. Replace contents of file with new results.
>
>perldoc -f open
>
>
------------------------------
Date: Sun, 25 Jul 1999 04:09:22 -0400
From: Jeremy James <perly@ufl.edu>
Subject: Re: special problem
Message-Id: <379AC631.DD380C4A@ufl.edu>
Frank de Bot wrote:
> I want to do something weird ( I think ).
> I have a string which is called array:
>
> $string = "array";
>
> Now I want to create an array with that variable.
>
> @array = ""; # To put something in it is for later
>
> if I have a string whit the value "mp3" I want to create a array @mp3
>
> Is this possible?
>
> --
> Penpal International , Searchy.net
> http://www.debot.nl/ppi , http://www.searchy.net/
> ppi@debot.nl , support@searchy.net
I believe what you are looking for is a symbolic reference:
from perlref
$name = "foo";
$$name = 1; # Sets $foo
${$name} = 2; # Sets $foo
${$name x 2} = 3; # Sets
$foofoo
$name->[0] = 4; # Sets
$foo[0]
@$name = (); # Clears
@foo
&$name(); # Calls
&foo() (as in Perl 4)
$pack = "THAT";
${"${pack}::$name"} = 5; # Sets
$THAT::foo without eval
read the 'references' chapter of Programming Perl
------------------------------
Date: 25 Jul 1999 10:24:27 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: template
Message-Id: <7neokr$5df$1@lublin.zrz.tu-berlin.de>
pringles <nada818s@powerup.com.au> wrote in comp.lang.perl.misc:
>Periodical
>
>Publication with a distinctive title intended to appear in successive
>numbers or parts at stated or regular intervals for an indefinite time.
>==============================================================
Come again?
>Please take a look at www.jumbomall.com/kevin and click on template buttom.
I did. It re-displays the map that was on the first page, but nothing
else. Is that what it's supposed to do? There's no way to tell.
>This is my problem:
>
>How do I get it display on my site:
Get what to display?
>I have problem with template:
>This is the code in test0.pl under the cgi-bin directiory
>
>sub template{
> my ($filename, $fillings) = @_;
> my $text;
> local $/; #slup mode(undef)
> local *F; #create local filehandle
> open(F, "< ./filename.txt")||return;
> $text = <F>; #read whole file
> close(F); #ignore retval
>
> #replace quoted words with value in %$fillings hash
> $text =~s{%%(.*?)%%}
> {exists($fillings->{$1})
> ?$fillings->{$1}
> :""
> }gsex;
> return $text;
>}
The code looks fine to me, as far as it goes, though I don't think
the /x modifier is really needed in the regex. Is that all there is
in text0.pl? If so, the subroutine template is never called. The
script does nothing.
>I have the filename.txt in the same directory
>the is what I have inside
>
><!--simple.template for internal template() function -->
><HTML><HEAD><TITLE>Report for %%username%%</TITLE></HEAD>
><BODY><H1>report for %%username%%</H1>
>%%username%% logged in %%count%% times, for a total of %%total%% minutes.
But your script knows nothing about this file. You will have to
put the path name to the file in a variable:
$file = '/path/to/cgi-bin/filename.txt';
You'll further have to set up a hash with replacements for %%username%%
etc, somewhat like this:
my $replacements = {
username => 'nada818s',
count => 23,
total => 1440,
};
Now call template like this:
$result = template( $file, $replacements);
After that, you'll have to print $result, probably after printing some
required headers -- this is not my field.
print $result;
Well, that should be it.
>I complie the test0.pl with no error. How do I call this test0.pl from the
>webpage?
This isn't a perl question. From a cursory glance it seems you are
calling it alright. You'd never know, because the script doesn't do
anything.
>this line in html <FORM action = "http://...gi-bin/kevin/test0.pl"> doesn't
>work,
>
>I don't want to do it in a html FORM method because my second webpage is
>just for display.
>
>How can I call the test0.pl form it?
All this has nothing to do with perl. Ask a group that has html or cgi
in its name.
Anno
------------------------------
Date: Sun, 25 Jul 1999 16:31:02 +0700
From: Marco Ender <info@servicepool.de>
Subject: Re: Waiting for system ??
Message-Id: <379AD956.701F4ED7@servicepool.de>
Im sorry, i made an error :-) i haven't written the code i use only i
have
typed it plain, to spot my problem, the script is working the only thing
that isn't working ist the WAIT that i need, i have all ; " ... .
Here is the Script i want to use :
#!/usr/bin/perl5
#
#
#
$getprog = "wget";
$tmpfile = "/web/test/test.txt";
&HTML_BEGINN;
opendir(DIR,"/web/test/file");
while ($name = readdir(DIR))
{
push (@datei, $name);
}
close (DIR);
shift(@datei);
shift(@datei);
for (@datei){
$updatei=$_;
open (FILE ,"</web/test/file/$updatei");
$filedat=<FILE>;
close (FILE);
@dats=split(/;/, $filedat);
$get = `$getprog $dats[4] -O $tmpfile`;
print "<p>Oeffne $dats[4]</p>";
open (HTML, "<$tmpfile");
while (<HTML>){
$html=$_;
print "<p>Suche ...</p>\n";
print "<p>$get</p>\n";
if ($html =~ /BEGINN_CODE_XX1/) {
push (@treffer, $_);
print "<p>Code gefunden !<p>";
}
}
close (HTML);
system `rm $tmpfile`;
}
The Script runs good, only it don't wait for wget to finish the
download, so i have at the end only two
or three files scanned, from about 1000 HTML-Files.
Again Thanks.
By Marco
Anno Siegel wrote:
>
> Marco Ender <info@servicepool.de> wrote in comp.lang.perl.misc:
> >Hy ,
> >
> >i have a small problem with a script, how can i force the script to wait
> >until a system proggy has done his work commpletly.
>
> Run-on sentence. Missing question mark. And you have a *big* problem
> with your script.
>
> system() does wait for the process. What makes you think it doesn't?
> If the reason is that the output file doesn't seem to be there, see below.
> Come to think of it, see below anyway.
>
> >for (@filename){
> > system wget $_ -0 filenamelocal.txt
>
> This should be
>
> system "wget $_ -0 filenamelocal.txt";
>
> Don't use barewords. If you'd switched warnings on as recommended,
> you'd have spotted this. If you'd used strict, it wouldn't even
> have compiled, a good thing in this case. Well, actually your code
> didn't compile anyway because you're missing a ";" at the end of
> of the line. Are you're not showing us the code you actually use?
> How do you suppose us to spot your errors?
>
> Anyway, the file name the system command sees is "filenamelocaltxt",
> not "filenamelocal.txt" as you probably believe. Look up the dot
> operator to see why.
>
> > ----------> here i need WAIT ontil wget is finished.
>
> No, you don't.
>
> > open (FILE, filelocal.txt)
>
> The open isn't going to work because you have written to
> "filenamelocaltxt" but try to read from "filelocaltxt". But
> you'll never know because you are not checking open() for success.
> Well, it doesn't compile either, because another ";" is missing. Use
>
> open( FILE, "filenamelocal.txt") or
> die "Can't read filenamelocal.txt: $!\n";
>
> Better yet, put your filename in a variable to use whenever you
> need the filename. That way you wouldn't be trying to read from
> a file you didn't create in the first place.
>
> > .....
> > .....
> > ....
> > close (FILE)
>
> Another ";" missing. You don't need to close a filehandle if you're
> going to re-open it next thing. A single close() after the loop would
> have been enough. But that may be a matter of style.
>
> >system remove filelocal.txt;
>
> More barewords. And why do you want to delete the file if you're
> going to overwrite it anyway the next time through the loop? Again,
> it would have been enough to remove it once after the loop, of course
> using Perl's very own unlink() for the purpose, not a system call.
> Also, why don't you indent that line like the others inside the loop?
>
> >}
> >
> >
> >Thx Marco
>
> For nothing.
>
> For those who have read the very recommendable
>
> http://www.plover.com/~mjd/perl/Questions.html
>
> this is an example of another type of badly posed question. The guy
> *thinks* he knows what's going on and limits the answers to the
> nonsensical "How can I make system() wait for the process to end?"
> He goes on to post code that is so bug-ridden, you want latex gloves
> to touch it. He hadn't got an answer on my feed and really doesn't
> deserve one. If I hadn't just come back from reading the above
> article about stupid questions, I'd have ignored it as well. However,
> I thought I'd try to give a thorough answer and see how it goes.
>
> Result:
> It took ridiculously long, and the time is almost certainly wasted.
> The poster's level of programming expertise is just too low to appreciate
> it, judging from what he posted. Actually the use of $_ after
> "for (@filename)" is about the only indication he at least partially
> knows what he's doing. And I'm sure there are more bugs than I've
> spotted.
>
> Oh, and I pointed out the run-on sentence in the beginning for a
> reason. These are a good indicator that what's following is likely
> to be garbage, as are questions followed by a period. It's the
> linguistic equivalent of missing semicolons in perl code, as it were.
>
> Anno
------------------------------
Date: 25 Jul 1999 11:28:35 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Waiting for system ??
Message-Id: <7nesd3$5gj$1@lublin.zrz.tu-berlin.de>
Marco Ender <info@servicepool.de> wrote in comp.lang.perl.misc:
>Im sorry, i made an error :-) i haven't written the code i use only i
>have
>typed it plain, to spot my problem, the script is working the only thing
>that isn't working ist the WAIT that i need, i have all ; " ... .
>
>Here is the Script i want to use :
Well, that looks a lot less icky than what you posted before. Lessee...
(And note my suggestions aren't tested)
>#!/usr/bin/perl5
You should use the -w switch, especially when you have problems. You
should probably also use strict, but then you'd have to sprinkle your
code with a lot of "my"s, and perhaps other things to make it run.
>#
>#
>#
>$getprog = "wget";
>$tmpfile = "/web/test/test.txt";
>&HTML_BEGINN;
I'll assume, HTML_BEGINN is defined somewhere in parts of the code you
don't show.
>opendir(DIR,"/web/test/file");
>while ($name = readdir(DIR))
> {
> push (@datei, $name);
push (@datei, $name) unless $datei =~ m/^\.\.?$/;
would be more robust. See below.
> }
>close (DIR);
>shift(@datei);
>shift(@datei);
I guess this is there to get rid of the . and .. directories. While
these are usually the first entries in a directory, they don't have
to be, so this isn't very robust.
>for (@datei){
> $updatei=$_;
> open (FILE ,"</web/test/file/$updatei");
open (FILE ,"</web/test/file/$updatei") or
die "Can't read $updatei: $!\n";
*Always* test open() for success, even if you're sure the file
exists. You may not have read permission, or the file may have
been deleted in the meantime, or.... You may want to say next
instead of die()ing, so you lose only those cases.
> $filedat=<FILE>;
You're reading only one line per file. I'll assume that's what
you want to do.
> close (FILE);
> @dats=split(/;/, $filedat);
> $get = `$getprog $dats[4] -O $tmpfile`;
This is where you think you have to wait, right? I still think
you don't.
You're using backticks here instead of system(), as you said
before. In terms of having to wait for the process to finish, that's
the same thing. Perl does that wait for you. Think about it: Perl
promises to put the output of the wget-command into your variable $get.
It couldn't do that if it didn't wait for wget to finish.
What you ought to do instead is check $? to see if wget ended normally.
(See perldoc perlvar for interpretation of $?.) I bet you'll find something
untoward.
> print "<p>Oeffne $dats[4]</p>";
> open (HTML, "<$tmpfile");
Again, check if open() worked.
> while (<HTML>){
> $html=$_;
> print "<p>Suche ...</p>\n";
> print "<p>$get</p>\n";
> if ($html =~ /BEGINN_CODE_XX1/) {
> push (@treffer, $_);
> print "<p>Code gefunden !<p>";
> }
> }
> close (HTML);
> system `rm $tmpfile`;
>
>}
>
>The Script runs good, only it don't wait for wget to finish the
>download, so i have at the end only two
>or three files scanned, from about 1000 HTML-Files.
While I don't know details about wget (except that it fetches files
given a url), unless it does something unusual like forking itself in
the background, this is certainly not because you failed to wait
for it to finish. Print out the url's you're using ($dats[ 4], I
suppose). Check them manually to see if they're correct. See if wget
can write a log file (I'd suppose it can) to get more information on
how it fares. Direct its stderr to a file. Be creative.
Good luck.
Anno
------------------------------
Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 1 Jul 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.
To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.
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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 250
*************************************