[8460] in Perl-Users-Digest
Perl-Users Digest, Issue: 2077 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 11 18:07:26 1998
Date: Wed, 11 Mar 98 15:00:30 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 11 Mar 1998 Volume: 8 Number: 2077
Today's topics:
Re: ?name=A+B <jkry3025@comenius.ms.mff.cuni.cz>
Re: Accessing password protected URL's with LWP <aas@sn.no>
Re: attachments <jkry3025@comenius.ms.mff.cuni.cz>
Re: Brand new and completely bewildered!!! <merlyn@stonehenge.com>
Re: Calling a CGI inside another CGI <zenin@best.com>
First Look-MS's New Windows Foundation Class <colby@earthweb.com>
Re: Formatting telephone numbers - How to? (Nickhead)
Re: Help: avoiding eval() on a grep() function. (Andrew M. Langmead)
Re: How do I rename a file using perl <spamfree@yahoo.com>
Re: How do I rename a file using perl <dagon@halcyon.com>
Re: How to embed special characters in replacement stri (Hunter Johnson)
Re: How to use multipart with libwww? <aas@sn.no>
Multipart Content Header? <peter@webcanada.com>
Re: multiple blank lines into one (Hunter Johnson)
Multiple Variable Reference slafran@ibm.net
Re: nslookup? (David Wall)
Re: Perl equivalent for /bin/which <merlyn@stonehenge.com>
Perl for Windows (Was: Re: Completely Stumped) <ludlow@us.ibm.com>
Re: PGP / $PGPPASS <zenin@best.com>
Re: PID of process launched in unix system? (Clinton Pierce)
Re: PID of process launched in unix system? (Erik Johnson)
Re: Problem with "goto" in Perl <zenin@best.com>
Re: Problem with "goto" in Perl <zenin@best.com>
Re: Problem with "goto" in Perl <zenin@best.com>
Re: Speed of sort routine vs. one-by-one compare (123 (Bart Lateur)
Re: Spitting out MIME types <hsommer@micro.ti.com>
Re: splice -- useful uses? <merlyn@stonehenge.com>
Re: splice -- useful uses? (Andrew M. Langmead)
Re: system(command) = fork + exec(command)? kill parent <jdaza@idecnet.com>
Re: system(command) = fork + exec(command)? kill parent <andrew@erlenstar.demon.co.uk>
Time delayed response (Mark Waterous)
Re: Update another frame from Perl script. <rjk@coos.dartmouth.edu>
Re: What command Calls a prog on the web? <jim.michael@gecm.com>
Re: What command Calls a prog on the web? (Clinton Pierce)
Why no "next/last/redo" with do? (Kevin White)
Re: Wierd redirection problem with Location: (Fallout23)
Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 11 Mar 1998 23:27:06 -0800
From: Jan Krynicky <jkry3025@comenius.ms.mff.cuni.cz>
Subject: Re: ?name=A+B
Message-Id: <35078E4A.479F@comenius.ms.mff.cuni.cz>
Arnoud de Jong wrote:
>
> Hi
>
> Suppose i have name with spaces included (Arnoud de Jong). Now I want to
> create a link to another .pl that would look like this :
> dosomething?name=Arnoud+de+Jong
>
> How can I change the <space> to <+>?
>
> Arnoud
As Steve pointed out there are modules for that. If you find CGI.pm
too general for your needs you may want to use some tiny module
that does onle the encoding. See http://www.chipnet.cz/depot/perl.htm
for Deurl.pm nad Enurl.pm.
In this case it would be :
use Enurl;
$URL = 'dosomething?'
. enurl({name => 'Arnoud de Jong',
from => 'Netherlands'
});
# or
# $URL = 'dosomething?'
# . enurl 'name=Arnoud de Jong'
# . '&'
# . enurl 'from=Netherlands'
print "$URL\n";
which will give you
dosomething?name=Arnoud+de+Jong&from=Netherlands
HTH, Jenda
------------------------------
Date: 11 Mar 1998 21:46:42 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: Accessing password protected URL's with LWP
Message-Id: <m33egphs5p.fsf@furu.g.aas.no>
neal@make-a-store.com writes:
> Do I need any additional HTTP headers for this to work?
Try setting:
$req->authorization_basic('some user', 'some password');
before you send the request.
--
Gisle Aas
------------------------------
Date: Wed, 11 Mar 1998 23:31:01 -0800
From: Jan Krynicky <jkry3025@comenius.ms.mff.cuni.cz>
Subject: Re: attachments
Message-Id: <35078F35.2CEE@comenius.ms.mff.cuni.cz>
Robert wrote:
>
> Does anyone know if it is possible to attach a simple textfile to a
> mail message using sendmail or blat ?
>
> The reason I want to do this is because I want people to fill out a
> form. The data from that form will be written in a file that I want to
> attach to a mailmessage.
>
> Is this posible ?
>
> Robert
Don't know about sendmail, but you SHOUL NOT use external
programs unless realy necessary.
See http://www.chipnet.cz/depot/perl.htm for Mail::Sender.
It uses direct socket() connection to a SMTP server
and allows for easy attaching of files (not only textual).
Jenda
(Yes the author :-)
------------------------------
Date: 11 Mar 1998 15:25:38 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: guenzel.p1@usa.net (Bjoern Guenzel)
Subject: Re: Brand new and completely bewildered!!!
Message-Id: <8cvhtkn9ul.fsf@gadget.cscaper.com>
>>>>> "Bjoern" == Bjoern Guenzel <guenzel.p1@usa.net> writes:
Bjoern> I have downloaded several CGI-documentations and tutorials, but I
Bjoern> haven't come across 'statelessness'. What does it mean? Maybe then I
Bjoern> finally could make some sense of all this stuff :-)
Bjoern> I admit that I haven't got CGI.pm yet, I promise it's the next thing
Bjoern> I'll get.
There's nothing particularly perl-ish about this question, so this
is best asked in ciwac. However, since ciwac will kill you for asking
such a basic question, I'll answer it here in two ways.
One, the simplest, is go read my WebTechniques online columns, which
addresses this issue in various ways:
http://www.stonehenge.com/merlyn/WebTechniques/
Two, in brief, there's no real thing as "logging in" to a web server
at a basic level. Every fetch from a browser is a completely
independent transaction. Thus, if you want to have the appearance of
a "session", you have to figure out how to tell the browser to let you
know it's the same browser during subsequent visits. The most
portable of these is mangled-urls and hidden fields in forms, but you
can also (try to use) cookies (horrors! please don't!). My columns
talk about these. So I won't repeat that here.
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 173 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: 11 Mar 1998 21:29:01 GMT
From: Zenin <zenin@best.com>
Subject: Re: Calling a CGI inside another CGI
Message-Id: <889652119.137374@thrush.omix.com>
Craig Keefner <keefner@kinetic.com> wrote:
: I've tried exec("oracle.pl"; but I haven't
: got it to work yet without a server error.
: It works fine on a normal submit/post.
>snip<
Hmm, have you tried using the full path to "oracle.pl"?
exec "/full/path/to/oracle.pl";
die "Can't Happen[tm]: $!";
Don't assume that you're CGI program is called with the cwd set to
the directory of the script, because it rarely if ever is. Same
goes for anything in a crontab, and other utilities.
--
-Zenin
zenin@best.com
------------------------------
Date: Wed, 11 Mar 1998 17:22:23 -0500
From: Colby Cooper <colby@earthweb.com>
Subject: First Look-MS's New Windows Foundation Class
Message-Id: <35070E9F.A9BB519E@earthweb.com>
Thought you'd find this interesting...
MS had announced the release of the new feature set to the Visual J++
6.0 Technology Preview. You can read the first in-depth interview with
MS's top WFC architect, Anders Hejlsberg, check out the first available
WFC code samples and get all the technical details on this new
technology at developer.com.
------------------------------
Date: Wed, 11 Mar 1998 22:48:25 GMT
From: nickf@ptd.net (Nickhead)
Subject: Re: Formatting telephone numbers - How to?
Message-Id: <350713f7.315307@news.ptd.net>
On 5 Mar 1998 16:04:34 GMT, "Joanne James" <jjames@netguild.com>
wrote:
>Hi. I'm helping out on a project using Perl and am learning as I go. I've
>been trying to show telephone numbers (numbers only are stored on database
>-no
>dashes) on an html page with dashes inserted. The database contains both
>US and international phone numbers. I want to put in dashes as in the
>following:
>999-999-9999 in all cases. I just need an example. Assume you are getting
>a field from an Oracle database and want to put it into an array (I
>presume), then insert the dashes. How would you do it? I have been trying
>for hours to get this to work! I would appreciate some feedback. Thanks
>for the
>help!
>
>
I'm doing this with a CGI script to a mysql database....and just split
the number into 3 parts :
$area = substr($phone, 0, 3);
$exch = substr($phone, 3, 3);
$num = substr($phone, 6, 4);
Then just format as 3 fields seperated by - .
This also adds flexibility to search on specific area codes too....
Nick
------------------------------
Date: Wed, 11 Mar 1998 22:35:42 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Help: avoiding eval() on a grep() function.
Message-Id: <EpoErI.CzE@world.std.com>
schwern@starmedia.net writes:
>In article <EpKL82.15D@world.std.com>,
> aml@world.std.com (Andrew M. Langmead) wrote:
>> Subroutine dereferencing and calling is fairly expensive too, and
>> should probably also be avoided inside of grep. Trading an eval for a
>> sub de-reference probably isn't that big of a win.
>Problem is... you need it. You can't do "grep { m/$STR1/ && m/$STR2/ }
>@array" because we don't know how many $STR's there will be in this case.
But you can build the string that not only contains the anonymous sub
and all of the matches, but also the grep(). Then after you eval the
string, you can call the anonymous sub to do the grep. This way, you
only have one dereference per grep() rather than one per element of
@Array.
my $regexs = join ' && ', map { "/$_/i" } @matches;
my $matchSub = eval "sub { grep { $regexs } \@Array";
Sorry for the messed up code in the previous post. I made the mistake
of making some "innocent" changes after I ran it and got the results
wanted and didn't notice the mistakes in later runs. (Making "@Array"
a file scoped variable hid it from the code ran from "timethese()")
This is why the "loop_eval" had the much lower time that it had in the
buggy code. Since the package variable @Array was empty, the eval was
never called.
#!/usr/bin/perl -w
use strict;
use Benchmark;
use vars qw($STR1 $STR2 @Array);
@Array = (`cat /usr/dict/words`)[0..100];
chomp(@Array);
$STR1 = 'a';
$STR2 = 'q';
my %subs = (one_eval => q(eval "grep { /$STR1/i && /$STR2/i } \@Array";),
loop_eval => q(grep { eval "/$STR1/i && /$STR2/i" } @Array;),
sub_match => q(
my $matchSub = eval "sub { /$STR1/i && /$STR2/i }";
grep {&$matchSub} @Array;
)
);
timethese ( 10_000, \%subs);
__END__
Benchmark: timing 10000 iterations of loop_eval, one_eval, sub_match...
loop_eval: 717 secs (708.20 usr 1.14 sys = 709.34 cpu)
one_eval: 46 secs (45.58 usr 0.10 sys = 45.68 cpu)
sub_match: 58 secs (56.81 usr 0.66 sys = 57.47 cpu)
Obviously since the only substantial difference between loop_eval and
sub_match is the dereferencing (otherwise they both have one eval
STRING, and one grep, and they both interpolate the regular
expressions into constant strings before compilation) the difference
in run time will be proportional to the number of elements in @Array.
--
Andrew Langmead
------------------------------
Date: Wed, 11 Mar 1998 17:03:16 -0500
From: Dave Bushong <spamfree@yahoo.com>
Subject: Re: How do I rename a file using perl
Message-Id: <35070A23.B3F63B75@yahoo.com>
Abigail wrote:
> arzoo@ids.net (arzoo@ids.net) wrote on 1653 September 1993 in
> <URL: news:6e6g20$m32$1@nnrp1.dejanews.com>:
> ++ I want to rename a file using a PERL script that takes an input from a HTML
> ++ [...]
> Ah, yes, that's one of the mysteries of Perl. To rename a file, you
> actually don't use a function called rename () (you did notice that perldoc
> -f rename only resulted in an ascii image of a funny face, didn't you?),
[biteme!dbushong 376] perldoc -f rename
Unknown option: f
perldoc [-h] [-v] [-u] PageName|ModuleName|ProgramName...
-h Display this help message.
-t Display pod using pod2text instead of pod2man and nroff.
-u Display unformatted pod text
-m Display modules file in its entirety
-v Verbosely describe what's going on.
PageName|ModuleName...
is the name of a piece of documentation that you want to look at. You
may either give a descriptive name of the page (as in the case of
`perlfunc') the name of a module, either like `Term::Info',
`Term/Info', the partial name of a module, like `info', or
`makemaker', or the name of a program, like `perldoc'.
Any switches in the PERLDOC environment variable will be used before the
command line arguments.
[biteme!dbushong 377] perldoc rename
No documentation found for 'rename'
Great tip. Except I didn't even get a dinosaur.
------------------------------
Date: 11 Mar 1998 14:01:34 -0800
From: Mark Rafn <dagon@halcyon.com>
Subject: Re: How do I rename a file using perl
Message-Id: <6e71ju$72d$1@halcyon.com>
Holly Sommer <hsommer@micro.ti.com> arranged electrons in a pattern like this:
>Whoa, you made yourself alot of work there. Just do this:
>
>$file1 = "/path/to/file/one";
>$file2 = "/path/to/file/two";
>$err = `mv $file1 $file2`;
Umm...Any reason to call an external program?
The simple version will work if you're not crossing filesystems.
rename file1, $file2 || die "rename: $!";
The better version is much more robust.
use File::Copy;
move($file1, $file2) || die "move: $!";
--
#!/usr/bin/perl -- # Mark Rafn dagon@halcyon.com
&ja('&*MQ))U=@','&*HBM4E90','&JDCK4G1@','&1,BI(E=0');&ja('&SLBD:NP`',
'&K*BJC,H`','&R,CNBHP`','&CJRJ:NH`');sub ja{for$c(@_){$d=unpack('B48',
unpack('u',$c));$d=~tr/10/@ /;print"$d\n"}print"\n"}
------------------------------
Date: 11 Mar 1998 21:19:43 GMT
From: jhunterj@lexis-nexis.com (Hunter Johnson)
Subject: Re: How to embed special characters in replacement string?
Message-Id: <6e6v5f$g1a@mailgate.lexis-nexis.com>
In article <6e1bjs$hap$1@hecate.umd.edu>, Leon Poon <lpoon@Glue.umd.edu> wrote:
> How does one embed special characters like \n, \t, etc. in the
> replacement string and have it interpreted by perl?
Have you tried *anything*?
Use \n for \n, \t for \t, etc.
Hunter
--
J. Hunter Johnson | "A little consistent wholesome modeling and
jhunterj@lexis-nexis.com | costly servanthood are worth millions of
(937) 865-6800 x5385 | true words harshly spoken."
Lexis-Nexis, Dayton, OH | -- Ron Sider
------------------------------
Date: 11 Mar 1998 21:50:56 +0100
From: Gisle Aas <aas@sn.no>
Subject: Re: How to use multipart with libwww?
Message-Id: <m3zpixgde7.fsf@furu.g.aas.no>
md4calle@mdstud.chalmers.se (Carl ]sman) writes:
> I shall upload some 1000 files via a webpage (not my idea at all,
> they refuse to do it in any other way), and that webpage uses
> multipart for the uploading procedure.
No problem.
> I wonder how I shall write a script that will do this for me,
> it shall call the webpage and upload each file, in the same manner
> is if I was doing it from a webbrowser.
>
> Anyone tried something like this and got any tips?
Take a look at HTTP::Request::Common module and the constructor
function provided called POST. It allows you to easily create
multipart/form-data requests.
> Shall I make a request with the file attached to it somehow, I don't
> get it really....
Yes.
--
Gisle Aas
------------------------------
Date: Wed, 11 Mar 1998 16:29:17 -0500
From: Peter <peter@webcanada.com>
Subject: Multipart Content Header?
Message-Id: <3507022D.3C7388BA@webcanada.com>
Hey everyone,
I want to do something in a Perl script similar to what Microsoft has
done in Expedia (and Continental Airlines in their online schedule)..
How their database search works is: you type in your search criteria and
submit, a *temporary* screen is sent back saying the database is
searching, and once the results are available, the script sends a new
page to the browser.
When you click on View Source, the previous temporary page source is not
there. This is NOT a META tag thingy...
I'm guessing they did it with a Multipart Content-type Header.... but I
can't find any info on how to do this.
If anyone can help please respond (CC: by e-mail) ..
peter@webcanada.com.
Thanks,
Peter.
------------------------------
Date: 11 Mar 1998 21:28:04 GMT
From: jhunterj@lexis-nexis.com (Hunter Johnson)
Subject: Re: multiple blank lines into one
Message-Id: <6e6vl4$h9r@mailgate.lexis-nexis.com>
In article <6e5ifl$6ij$1@gondor.sdsu.edu>,
SenimotBor <tomines@rohan.sdsu.edu> wrote:
> I'm sure this is a simple newbie question but I've been racking my
> brain for an answer and have had no success.
> How do you substitute multiple consecutive blank lines for one blank
> line. I've tried the following but can't figure out what I'm doing
> wrong.
This is a Common Task With Perl: Printing a File with Multiple Blank
Lines Squeezed Into One.
perl -ne 'print if /\S/ || !s; $s = /^\s*$/;'
Note that blank lines here can have whitespace, which your regexps
didn't allow.
The (main?) problem with your regexps is that they expected to have
more than one line in the pattern, which is not the default.
Hunter
--
J. Hunter Johnson | "A little consistent wholesome modeling and
jhunterj@lexis-nexis.com | costly servanthood are worth millions of
(937) 865-6800 x5385 | true words harshly spoken."
Lexis-Nexis, Dayton, OH | -- Ron Sider
------------------------------
Date: Wed, 11 Mar 1998 16:01:42 -0600
From: slafran@ibm.net
Subject: Multiple Variable Reference
Message-Id: <6e71hq$4q5$1@nnrp1.dejanews.com>
This is my problem:
$TEMP00=1;
$TEMP01=2;
$TEMP02=3;
$TEMP10=4;
$TEMP11=5;
$TEMP12=6;
$TEMP20=7;
$TEMP21=8;
$TEMP22=9;
for($I=0; $I<3; $I++){
for($J=0; $J<3; $J++){
$TEST="\$TEMP"."$I"."$J";
?? How can I print my variables "as is" with my prebuild variable handler
$TEST, and possibly put it in a array ex $TEST = $ARRAY[X] were $TEST would
be replace by the variables on-top.
Right now $TEST generate the right variables names "$TEMP00 to $TEMP22".
}
}
exit;
Any help will be greatful.
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/ Now offering spam-free web-based newsreading
------------------------------
Date: Wed, 11 Mar 1998 21:37:33 GMT
From: dkw0@cdc.gov (David Wall)
Subject: Re: nslookup?
Message-Id: <6e70gi$2nc1@cdc4.cdc.gov>
In article <6e6oco$8uh$1@was.hooked.net>, Jon Drukman <jsd@hudsucker.gamespot.com> wrote:
>------------------------
>#!/usr/local/bin/perl -w
>
>use Socket;
>
>$packed_version=gethostbyaddr('hudsucker.gamespot.com');
>$ascii_version=inet_ntoa($packed_version);
>------------------------
>
>gethostbyaddr returns its result in a packed format, suitable for
>handing off to various kernel TCP/IP routines. inet_ntoa translates
>the packed format into a human-readable one.
I think there's a typo there -- shouldn't that be gethostbyname?
David Wall
------------------------------
Date: 11 Mar 1998 15:33:42 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: "Stephane Barizien" <NOSPAM.stephane.barizien@ocegr.fr>
Subject: Re: Perl equivalent for /bin/which
Message-Id: <8cn2ewn9h5.fsf@gadget.cscaper.com>
>>>>> "Stephane" == Stephane Barizien <NOSPAM.stephane.barizien@ocegr.fr> writes:
Stephane> Maybe (probably) a newbie's question: how do I perform the equivalent of
Stephane> /bin/which (or, for Korn Shell addicts, the equivalent of "whence" or
Stephane> "type") in a Perl program?
Stephane> I can of course parse $ENV{"PATH"} myself, but there sure is a
Stephane> simpler-don't-reinvent-the-wheel method out there (CPAN?)
I do a "super" version of whence looking for duplicated elements
in the PATH (called "pathfinder" because I wrote it while watching
the Mars rover stuff). It's in my Unix Review columns online at
http://www.stonehenge.com/merlyn/UnixReview/
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 173 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 11 Mar 1998 15:55:04 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Perl for Windows (Was: Re: Completely Stumped)
Message-Id: <35070838.100CD00F@us.ibm.com>
David wrote:
>
> Please Help,
Ok, I'll help. In fact, I'll help you help yourself. You made no
mention at all of what OS you were using, but you did use the word
"notepad" so I'll assume that you use Windows. (BTW: If this is the
case, a better subject line might have been "Installing Perl on Windows"
since "Completely Stumped" conveys no useful meaning at all.)
Check out (and read the information at) the following links. It should
get you going.
http://www.activestate.com/
http://www.perl.com/
Note: If you use the Activestate version, you have to (1) download it,
(2) unzip it, and then (3) run the installer. If you don't run the
installer, it won't work. Also keep in mind that while it is possible
to double click on a Perl script to execute it, you really should run it
from a command prompt (MS-dos window). Also, please save yourself many
future problems by always using the "-w" switch. All of my Perl scripts
start with the following line:
#!/usr/bin/perl -w
In a dos window, you'd type something like:
d:\perl\scripts>perl myscript.pl
The FAQ and the documentation that comes with Perl can answer almost
every question you can imagine about getting started with Perl
(including this one).
Good luck to you. Happy scripting.
--
James Ludlow (ludlow@us.ibm.com)
This isn't tech support and all opinions are my own.
------------------------------
Date: 11 Mar 1998 21:57:19 GMT
From: Zenin <zenin@best.com>
Subject: Re: PGP / $PGPPASS
Message-Id: <889653817.449488@thrush.omix.com>
sentinel@spprod.se wrote:
: $ENV{'PGPPASS'} doesn't work either.
>snip<
Yes, this does work. I use it in my code. Show us your code and
we'll have a much better idea about what your trouble is.
--
-Zenin
zenin@best.com
------------------------------
Date: 11 Mar 1998 20:53:38 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
Subject: Re: PID of process launched in unix system?
Message-Id: <6e6tki$bui2@eccws1.dearborn.ford.com>
In article <3506DD28.CA74274A@micro.ti.com>,
Holly Sommer <hsommer@micro.ti.com> writes:
>A *really* quick-n-dirty would be something like:
>
> @commands = ("kill", "-9", "$pid");
>
>close(PS);
>
>Greater minds will undoubtedly have better solutions. This one has
>no error-checking either (on the open() or system()).
No greater mind, but killing with a "9" is probably unnecessary at least
and dangerous at worst. A TERM or HUP would be adaquate and a lot more things
get "cleaned up" by the system afterwards. Don't use a Bazooka when
a .45 will do nicely. :-)
.and besides. What if you have a bug and somehow $pid resolves to a
1? or 0? If it's ever run by root, sending a KILL to your process group
is kinda rude.
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: Wed, 11 Mar 1998 21:45:09 GMT
From: erik@phidias.colorado.edu (Erik Johnson)
Subject: Re: PID of process launched in unix system?
Message-Id: <35070589.164681900@news.colorado.edu>
On Wed, 11 Mar 1998 12:51:20 -0600, Holly Sommer
<hsommer@micro.ti.com> wrote:
>A *really* quick-n-dirty would be something like:
>
>open( PS, "| ps -ef" ); # or use whatever switches you
> # have available to you for ps
>while(<PS>) {
> if (/$processname/) {
> # adjust split as necessary for your ps results
> ($uid, $pid, $otherstuff) = split( / /, $_, 3);
> @commands = ("kill", "-9", "$pid");
> system(@commands);
> }
>}
>
>close(PS);
>
>Greater minds will undoubtedly have better solutions. This one has
>no error-checking either (on the open() or system()).
Thanks, I ended up doing something similar (i.e. parsing ps results
and using -o to limit the output to all I needed).
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Erik Johnson erik@ phidias.colorado.edu
http://phidias.colorado.edu/ejvgallery
http://phidias.colorado.edu/phidias
------------------------------
Date: 11 Mar 1998 22:13:13 GMT
From: Zenin <zenin@best.com>
Subject: Re: Problem with "goto" in Perl
Message-Id: <889654770.862884@thrush.omix.com>
Andrew M. Langmead <aml@world.std.com> wrote:
: Since I can't think of any changes in control flow that were added by
: perl 5. (except for "goto &$SUBROUTINE")
>snip<
I consider the entire object layer an additional form of flow
control (let the flames fly on that one! :-). Goto's in perl4
are oftin used for cleanup, and automatic object destruction
fills most (though not all, I'll agree) of these needs, even if
you don't code in an OO style.
: I can't see how perl3/4 compatibility could be an issue.
See above comments. Resource cleanup was not as clean in perl4 as
perl5, even without using OO code yourself. -Although, it normally
requires that you use other peoples objects, even if you don't
treat them like objects (such as IO::File objects instead of "real"
handles).
>snip<
: 1. I believe in the language-blind statement that not all gotos are
: evil and that they should be judged in context.
>snip<
Agreed, which is why I asked for examples. In C there are vary
valid reasons to use goto, mostly for speed but some of which are
for cleaner code. Perl does not have any speed issues (that I've
ever seen) that a goto would help, and perl5 features make most
"cleaner" code much cleaner if you don't use gotos.
IMHO of course. :-)
: 3. I haven't found a situation where opinion #2 hasn't won over
: opinion #1, but since #1 requires you to examine each and every
: example, I won't be able to say for sure until I find an example where
: #2 doesn't apply.
Agreed. All tools are useful, for something... In perl however,
goto is an vary, vary limitedly useful tool. Far more limited then
most other languages.
--
-Zenin
zenin@best.com
------------------------------
Date: 11 Mar 1998 22:25:46 GMT
From: Zenin <zenin@best.com>
Subject: Re: Problem with "goto" in Perl
Message-Id: <889655524.467335@thrush.omix.com>
Tony Fitzgerald <jaf@sarastro.unb.ca> wrote:
: Rather than be a slave to goto dogmas, I've found the following methodology
>snip<
And this is better then continue, next or a for() loop how, exactly?
: I would hate to lose a tool a useful as the very sparing use of goto because
: of the religious fanaticism of the anti-goto camp.
I'm not saying that the godo opt code should be removed from perl.
What I'm saying is that as soon as you think your code needs a goto
for pretty much anything other then goto &$sub, you should probably
go out for a cup of coffee, maybe read a little bit of Kerouac. If
you come back in 15 or 20 minutes and still think that goto is a
Good Thing[tm], repeat the process once or twice. If at this point
you still feel that's it's a Good Thing[tm], post your code to
c.l.p.m and see if others agree and can't find a Better Way[tm].
Only after all that fails, should anyone ever consider there
particular use of goto the Best Way[tm] for the job at hand.
I'm not saying it's never the Best Way[tm], I'm just saying that in
99.9% of the cases, it's not. Since there still is that .1% of use
that is fully vaild, it should be left in. :-)
--
-Zenin
zenin@best.com
------------------------------
Date: 11 Mar 1998 22:52:00 GMT
From: Zenin <zenin@best.com>
Subject: Re: Problem with "goto" in Perl
Message-Id: <889657096.881659@thrush.omix.com>
schwern@starmedia.net wrote:
>snip<
: From _Code Complete_ Chapter 16.1 "The Argument for gotos"
: "The goto is useful in a routine that allocates resources, performs operations
: on those resources, and then deallocates the resources. With a goto, you can
: clean up in one section of code. The goto reduces the likelihood of your
: forgetting to deallocate the resources in each place you detect an error."
This is what object destructors, lexical scoped variables,
continue blocks, eval/die handlers et al are great for.
: This kinda falls under the AUTOLOAD style goto &subroutine, and the "extreme
: error recovery" case.
Yes. As I've stated, this is a special case in Perl, and I don't
really count it as a normal form of goto. It really deserves it's
own keyword, IMHO to make this point more clear.
: Knuth's "Structured Programming with go to Statements" 1974 _Classics in
: Software Engineering_ edited by Edward Yourdon, basically its an article with
: a horde of examples made more efficient by eliminating gotos, and then a whole
: 'nother horde of examples made more efficient by adding gotos. :) How
: relevant any of these examples are to Perl5, I have no idea. I don't have the
: book handy.
In C, gotos can be used by good programmers to help make much more
efficient code. This does not apply to perl however. Perl doesn't
have the kind of direct memory access that allows goto's in C to
be used to such ends.
: One use I saw was in an error recovery for a one-shot script (which,
: admitidly, isn't the greatest source for good programming style.) Which went
: something like this...
>snip<
And this is better then a code block using continue, next, redo,
etc?
while (1) {
...hundred likes of code...
last; ## if we worked ok
} continue {
if ($CertainErrorCondition) {
...woops! Went boom...
...clean up, we're starting over...
} elsif ($OtherErrorCondition) {
...woops! Went boom some other way...
} else {
die "Can't Happen[tm]";
}
}
Not the way I would normally design such a problem, but it's at
least a similar version of the label code.
: Now, granted... if the program was properly designed in the first place, this
: goto wouldn't be necessary. But it was a one-shot script and an extra
: requirement was added in at the last moment (doncha love how those one-shot
: scripts always turn into all-day projects?) requiring this little hack.
It's a kluge, not a hack. Hacks are good, kluges are bad. :-)
With such an example, I have to quote Larry from Programming Perl.
'A Perl script is "correct" if it gets the job done before your boss
fires you.'. Anything that is a one-shot and then gets kluged into
something bigger I think falls into this category. :-) In such a
case, the kluge is a Good Thing[tm] because you keep your job. :-)
: Now,
: there are other possiblities. He could have wrapped the program in a labeled
: block and done a next LABEL or redo LABEL (wait... can you do that in a
: non-loop block?), but would that really have been any different from the
: goto? No.
Useing continue, you may not need the label. Even with a label and
goto, the code is easier to read because you know exactly what the
block is (hopefully you've indented it properly) and as such know
exactly where you're jumping. It's a loop condition either way, not
a jump to a random location in the middle of a block of code, which
is the most evil form of goto as the reader may have to search for
hours to find that spot. If you don't use a label, you also can't
run into name collision if someone else (or you...) decides to add
code that needs a label.
--
-Zenin
zenin@best.com
------------------------------
Date: Wed, 11 Mar 1998 21:05:09 GMT
From: bart.mediamind@tornado.be (Bart Lateur)
Subject: Re: Speed of sort routine vs. one-by-one compare (123)
Message-Id: <3507f6ee.3074371@news.tornado.be>
abigail@fnx.com (Abigail) wrote:
>Actually, the merge sort would be a different algorithm. Then you
>grab all the to be inserted records, sort them, and merge them
>with the sorted file, which leads to a Theta (M log M + N) algorithm.
It is a merge sort, but a border case. If you have just one record, I'd
say that IS a sorted set. And you merge this "set" with a pre-sorted
file.
Bart.
------------------------------
Date: Wed, 11 Mar 1998 15:52:15 -0600
From: Holly Sommer <hsommer@micro.ti.com>
Subject: Re: Spitting out MIME types
Message-Id: <3507078F.8E2CA27C@micro.ti.com>
Jeff Stewart wrote:
: Since I can't find a newsgroup dedicated to CGI programming
: (and if you feel like declaring where this post belongs, feel
: free)...
Yeah, check at comp.infosystems.www.authoring.cgi
-Holly
------------------------------
Date: 11 Mar 1998 15:31:48 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: klassa@aur.alcatel.com
Subject: Re: splice -- useful uses?
Message-Id: <8cra48n9kb.fsf@gadget.cscaper.com>
>>>>> "John" == John Klassa <klassa@aursgh.aur.alcatel.com> writes:
John> Either way, what do people use splice for? I know what it does
John> and how to use it, but I don't really have a handle on cool
John> places it might show up. I don't know of any handy perl idioms
John> that make use of it, for example.
Here's some of my favorite splice things:
# make @y a random-unsorted copy of @x:
{ my @Z = @x; @y = (); push @y, splice @Z, rand @Z, 1 while @Z }
# make @x be at most 10 elements:
splice @x, 10 if @x > 10;
# parse a hash by key/value pairs where each won't work
{ my @list = %hash; while (@list) { ($key,$value) = splice @list, 0, 2; ... } }
print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,990.69 collected, $186,159.85 spent; just 173 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details
--
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@teleport.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me
------------------------------
Date: Wed, 11 Mar 1998 22:42:44 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: splice -- useful uses?
Message-Id: <EpoF38.IBH@world.std.com>
klassa@aursgh.aur.alcatel.com (John Klassa) writes:
>Either way, what do people use splice for?
The first edition of programming perl showed something like this in
the "common taks with perl" section. It randomizes an array.
push @random, splice @orig, rand @orig, 1 while @orig;
--
Andrew Langmead
------------------------------
Date: Wed, 11 Mar 1998 22:08:48 +0100
From: Jorge Daza <jdaza@idecnet.com>
Subject: Re: system(command) = fork + exec(command)? kill parent, children?
Message-Id: <3506FD5F.89DEBE02@idecnet.com>
--------------A53E7C8C71307AAF62DCE4DD
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Barninga Z! wrote:
> >If system(command) = fork + exec(command),
> >then how can I get the PID of exec(command), not the
> >PID of the system(command) which is the parent of
> >the "command".
Hi there, I just wanted to say that "system()" it's NOT equal to "fork()
+ exec()".
system() returns control to the point after it was called.
exec() does NOT return.
just that...
--
Jorge Daza - jdaza@idecnet.com
---------- -----------------
--------------A53E7C8C71307AAF62DCE4DD
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<HTML>
Barninga Z! wrote:
<BLOCKQUOTE TYPE=CITE>>If system(command) = fork + exec(command),
<BR>>then how can I get the PID of exec(command), not the
<BR>>PID of the system(command) which is the parent of
<BR>>the "command".</BLOCKQUOTE>
Hi there, I just wanted to say that "system()" it's NOT equal to "fork()
+ exec()".
<BR>system() returns control to the point after it was called.
<BR>exec() does NOT return.
<P>just that...
<PRE>--
Jorge Daza - jdaza@idecnet.com
---------- -----------------</PRE>
</HTML>
--------------A53E7C8C71307AAF62DCE4DD--
------------------------------
Date: 11 Mar 1998 21:19:47 +0000
From: Andrew Gierth <andrew@erlenstar.demon.co.uk>
Subject: Re: system(command) = fork + exec(command)? kill parent, children?
Message-Id: <87hg557wng.fsf@erlenstar.demon.co.uk>
>>>>> "Jorge" == Jorge Daza <jdaza@idecnet.com> writes:
[Turn off your HTML posting.]
Jorge> Hi there, I just wanted to say that "system()" it's NOT equal
Jorge> to "fork() + exec()".
System is indeed equal to fork() + exec(), or more accurately equal
to fork() + exec() + waitpid() + some minor signal manipulations.
Jorge> system() returns control to the point after it was called.
Jorge> exec() does NOT return.
That's why the fork() is there.
Take a look at the C code for system().
--
Andrew.
comp.unix.programmer FAQ: see <URL: http://www.erlenstar.demon.co.uk/unix/>
or <URL: http://www.whitefang.com/unix/>
------------------------------
Date: Wed, 11 Mar 1998 21:56:06 GMT
From: mail@silas.hypermart.net (Mark Waterous)
Subject: Time delayed response
Message-Id: <3506e946.12021887@news.bctel.ca>
I'm currently in the process of teaching myself perl
programming and came across something I would like to do in a simple
script I am writing. Lets say the file outputs two lines of html
somewhere in the body, with simply:
print "<P> A paragraph for instance.</P>";
print "<P> Followed by another one, but...";
but I want it to delay for, say 2 seconds between outputting
the second print line, so it would come up in the browser 2 seconds
after the first. Also I have found a few good online resources for
learning perl, but if anyone has any personal favorites or places that
they would like to suggest for learning perl, by all means, do so.
_________________________________
Mark Waterous - Silas Productions
[http://silas.hypermart.net/]
(contact@silas.hypermart.net)
-- Tutorials - Information Archives --
-- Online Shopping - Services --
------------------------------
Date: Tue, 10 Mar 1998 22:43:14 -0500
From: Ronald J Kimball <rjk@coos.dartmouth.edu>
Subject: Re: Update another frame from Perl script.
Message-Id: <35060854.B10BBDA6@coos.dartmouth.edu>
A. Deckers wrote:
>
> Yes. Please read the relevant FAQs posted to
> comp.infosystems.authoring.cgi.
That should be
comp.infosystems.www.authoring.cgi
--
_ / ' _ / - aka - rjk@coos.dartmouth.edu
( /)//)//)(//)/( Ronald J. Kimball chipmunk@m-net.arbornet.org
/ http://www.ziplink.net/~rjk/
"It's funny 'cause it's true ... and vice versa."
------------------------------
Date: Wed, 11 Mar 1998 15:53:29 -0500
From: Jim Michael <jim.michael@gecm.com>
Subject: Re: What command Calls a prog on the web?
Message-Id: <3506F9C9.6AB3@gecm.com>
Psiberjack wrote:
> I want to know how to write a standard Perl program that will call a
> program on the web i(e cgi script)and store the results in a text file?
> Also is it possible to store results in standard text format and not HTML?
For the client side you can use the LWP module to send your POST or GET
request to the server.
For the server side processing of the request and to send the text back
to the client you can use the CGI.pm module.
You can find both of these on CPAN: http://perl.com/CPAN/ . A couple of
books to get you started:
Learning Perl
Web Client Programming With Perl
..both from http://ora.com
Also search dejanews on 'perl lwp cgi' and you might just find some more
info.
Cheers,
Jim
--
------------------------------
Date: 11 Mar 1998 20:48:51 GMT
From: cpierce1@cp500.fsic.ford.com (Clinton Pierce)
To: psiberjack@aol.com (Psiberjack)
Subject: Re: What command Calls a prog on the web?
Message-Id: <6e6tbj$bui1@eccws1.dearborn.ford.com>
[cc by mail]
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
In article <19980311201800.PAA28922@ladder03.news.aol.com>,
psiberjack@aol.com (Psiberjack) writes:
>
>This is probably a very basic question.
>
>I want to know how to write a standard Perl program that will call a
>program on the web i(e cgi script)and store the results in a text file?
>
>Also is it possible to store results in standard text format and not HTML?
----------------------------------------------------------------
A CASUAL SEARCH OF www.dejanews.com HAS REVEALED:
search words: text cgi write
Has reported 340 hits
MANY OF THESE EXAMPLES HAVE CODE, AND POINTERS TO THE APPROPRIATE
INFORMATION. YOU HAVE FAILED TO DO CASUAL OR CURSORY RESEARCH
INTO YOUR QUESTION.
----------------------------------------------------------------
Try:
www.perl.com FAQ's, specifically under CGI Programing, there are
several. (eg. The Idiot's Guide to Solving Perl CGI Problems)
The Blue Camel (Chapter 6)
Documentation for the CGI modules.
The newsgroup comp.infosystems.www.authoring.cgi
(HINT: try their FAQ's first)
*************************************************************************
************************** FREE RANDAL **********************************
*************************************************************************
--
+------------------------------------------------------------------------+
| Clinton A. Pierce | "If you rush a Miracle Man, | http://www. |
| cpierce1@ford.com | you get rotten miracles" | dcicorp.com/ |
| fubar@ameritech.net |--Miracle Max, The Princess Bride| ~clintp |
+------------------------------------------------------------------------+
GCSd-s+:+a-C++UALIS++++P+++L++E---t++X+b+++DI++++G++e+>++h----r+++y+++>y*
------------------------------
Date: 11 Mar 1998 17:00:18 -0500
From: kwhite@apache.tsc.ohio-state.edu (Kevin White)
Subject: Why no "next/last/redo" with do?
Message-Id: <6e71hi$2b7$1@apache.tsc.ohio-state.edu>
The footnote on the first page of chapter 9 (p. 101) in the Blue Llama
says this:
"Note that the do {} while/uttil construct does not count as a loop
for purposes of next, last, and redo."
My question (the obvious): why?
I've scoured the FAQ and the Blue Camel, and nothing. I did catch a
reference here once to justification for fixing that, but I'm curious
as to the logic that created the condition in the first place.
Kevin
------------------------------
Date: Wed, 11 Mar 1998 22:21:26 GMT
From: fallout@deltanet.com_remove_ (Fallout23)
Subject: Re: Wierd redirection problem with Location:
Message-Id: <35070e3f.160314962@news.deltanet.com>
On Wed, 11 Mar 1998 10:36:24 -0500, Dan Boorstein
<dboorstein@shopcfn.com> wrote:
>$u = "Location: http://www.cis.ohio-state.edu/htbin/rfc/rfc2068.html";
>print "$u\n\n";
If you are using PWS or IIS, it is also REQUIRED that you return the
status code 301 too. took me a while to figure that one out on my own.
-Mike
------------------------------
Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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 V8 Issue 2077
**************************************