[22849] in Perl-Users-Digest
Perl-Users Digest, Issue: 5070 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 3 18:10:43 2003
Date: Tue, 3 Jun 2003 15:10:12 -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 Tue, 3 Jun 2003 Volume: 10 Number: 5070
Today's topics:
Perl fork() question <reply@newsgroup.invalid>
Re: Perl fork() question <emschwar@pobox.com>
Re: Perl fork() question <Wolfgang_.fischer@freenet.de>
Re: Perl fork() question <reply@newsgroup.invalid>
Re: Perl fork() question <reply@newsgroup.invalid>
Re: Perl fork() question <emschwar@pobox.com>
Re: perlrun manpage should warn that -we is a lot diffe <nospam-abuse@ilyaz.org>
Re: perlrun manpage should warn that -we is a lot diffe <bik.mido@tiscalinet.it>
Posting to an asp form with hidden fields (Alan Hogue)
Reference types (Dave Pointon)
Re: Reference types (Tad McClellan)
Re: Remove first character in a string? <dbo@xbn.nl>
Re: Remove first character in a string? (Tad McClellan)
speed up loading of modules (cgi) <swen@news.com>
Unix to Win2k servers <devnull@pipex.com>
Re: Using "eval" with "my", works up to a point, then . <nospam-abuse@ilyaz.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Jun 2003 18:32:12 +0200
From: Prodigy <reply@newsgroup.invalid>
Subject: Perl fork() question
Message-Id: <bbiide$cnd$1@beast.euro.net>
Hello,
I wrote a script which builds serial IO::Sockets, but due to the fact that
it needs to build a lot of sockets, it takes very much time, since every
connection lasts for about 10 seconds.
Now I was thinking about forking the process, so that Perl could build about
10 sockets a time, to speed up some things. So, I started a little
experimenting with fork(), and found out pretty soon that you really need
to think about what you're doing (I wrote my first forkbomb in 5 minutes
;).
However, after playing with it a little bit, I couldn't get anything
functional for me. In short, this is what I wrote: first, the current PID
($$) is stored in the variable $parent, then I do fork(); and then there's
an if-statement looking at $$, and compairing it with $parent. If it
matches, it's the parent process, else it's the child process.
I'm stuck at the moment, because I don't 'see' how to get this working with
IO::Socket. I'm thinking about putting the amount of sockets to build in a
var (scalar @portnumbers), and putting the amount of maximum child
processes in a var, but I can't get anything to work. :-/
Please help me out here, Prodigy
------------------------------
Date: 03 Jun 2003 10:42:55 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Perl fork() question
Message-Id: <eto7k83un74.fsf@wormtongue.emschwar>
Prodigy <reply@newsgroup.invalid> writes:
> However, after playing with it a little bit, I couldn't get anything
> functional for me. In short, this is what I wrote: first, the current PID
> ($$) is stored in the variable $parent, then I do fork(); and then there's
> an if-statement looking at $$, and compairing it with $parent. If it
> matches, it's the parent process, else it's the child process.
Too much work! Just check the output of fork() to see if you're a
parent or a child. It's also more idiomatic and therefore more
maintainable. `perldoc -f fork` for more info.
> I'm stuck at the moment, because I don't 'see' how to get this working with
> IO::Socket. I'm thinking about putting the amount of sockets to build in a
> var (scalar @portnumbers), and putting the amount of maximum child
> processes in a var, but I can't get anything to work. :-/
I don't understand what you want to do. Are you just trying to fork()
just to create the sockets, and then somehow go back to the main
program and do something with them? If so, you can't get there from
here. If your perl is threaded, you might be able to (don't know, I
haven't played with perl threads).
Wait, I was wrong. You *could* do something like this:
1) open some pipe()s to read and write to the child.
2) fork()
3) (in the parent) write commands to the pipes to tell the child what
to do
4) (in the child) read those commands, and read/write the IO::Socket
object depending on what they say, and pass the results to the
parent through the pipe()s.
5) Cry, because this is too complex, and look for another solution.
If what you're trying to do is fork, then do everything with the
socket in the child process, you're fine.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Tue, 03 Jun 2003 18:58:19 +0200
From: Wolfgang Fischer <Wolfgang_.fischer@freenet.de>
Subject: Re: Perl fork() question
Message-Id: <pan.2003.06.03.18.58.18.854792.16564@freenet.de>
Hi,
maybe you should consider using asynchronous IO with one thread without
forking. Look perldoc -f ioctl for more details.
------------------------------
Date: Tue, 03 Jun 2003 21:55:16 +0200
From: Prodigy <reply@newsgroup.invalid>
Subject: Re: Perl fork() question
Message-Id: <bbiua6$jp4$1@beast.euro.net>
Wolfgang Fischer wrote:
> Hi,
> maybe you should consider using asynchronous IO with one thread without
> forking. Look perldoc -f ioctl for more details.
Thanks for your reply.
Hmm.. I read the perl documentation and both manual pages (2 and 9), but I
don't really understand how I can use ioctl for my application. In short
what I want: perl should build a socket to a remote host, do some things
(send data, receive data) and then return the received data in a variable
or something. At the moment, I'm doing this in serial but I want to do this
in parallel, is that possible at all?
- Prodigy
------------------------------
Date: Tue, 03 Jun 2003 21:58:09 +0200
From: Prodigy <reply@newsgroup.invalid>
Subject: Re: Perl fork() question
Message-Id: <bbiufi$jp4$2@beast.euro.net>
Eric Schwartz wrote:
> Prodigy <reply@newsgroup.invalid> writes:
>> I'm stuck at the moment, because I don't 'see' how to get this working
>> with IO::Socket. I'm thinking about putting the amount of sockets to
>> build in a var (scalar @portnumbers), and putting the amount of maximum
>> child processes in a var, but I can't get anything to work. :-/
>
> I don't understand what you want to do. Are you just trying to fork()
> just to create the sockets, and then somehow go back to the main
> program and do something with them? If so, you can't get there from
> here. If your perl is threaded, you might be able to (don't know, I
> haven't played with perl threads).
In short what I want: perl should build a socket to a remote host, do some
things (send data, receive data) and then return the received data in a
variable or something. At the moment, I'm doing this in serial but I want
to do this in parallel.
> Wait, I was wrong. You *could* do something like this:
>
> 1) open some pipe()s to read and write to the child.
> 2) fork()
> 3) (in the parent) write commands to the pipes to tell the child what
> to do
> 4) (in the child) read those commands, and read/write the IO::Socket
> object depending on what they say, and pass the results to the
> parent through the pipe()s.
> 5) Cry, because this is too complex, and look for another solution.
>
> If what you're trying to do is fork, then do everything with the
> socket in the child process, you're fine.
Hmm.. sounds very very complex :-/
Isn't there any easier way to achieve the thing I want?
Thank you for your reply, Prodigy
------------------------------
Date: 03 Jun 2003 15:19:01 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Perl fork() question
Message-Id: <etohe76uaey.fsf@wormtongue.emschwar>
Prodigy <reply@newsgroup.invalid> writes:
> In short what I want: perl should build a socket to a remote host, do some
> things (send data, receive data) and then return the received data in a
> variable or something. At the moment, I'm doing this in serial but I want
> to do this in parallel.
<snip my example>
> Hmm.. sounds very very complex :-/
> Isn't there any easier way to achieve the thing I want?
Well, it's really not all that complex. When you fork(), your child
processes have to have some way to return a value to the parent.
Since they're distinct processes, the only way to do it is by creating
some channel to communicate back to the parent. pipe() is ideal for
this, as it lets you use select() to read from the child processes.
You could do other things (temp files, SysV IPC, etc.), but they're
even worse.
I probably overcomplicated my example by postulating the child
processes are long-lived, but given your description above, it sounds
like you could set things up so that the child process has all the
info it needs from the parent before you fork(), and then just have
the one set of pipe()s to return data to the parent. Once the child
has returned its data, have it exit, and *poof*, you're done.
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Tue, 3 Jun 2003 20:05:43 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: perlrun manpage should warn that -we is a lot different than -ew
Message-Id: <bbiv2n$17gg$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Tad McClellan
<tadmc@augustmail.com>], who wrote in article <slrnbdjtss.dh3.tadmc@magna.augustmail.com>:
> > The perlrun manpage should warn that using -we is a lot different than -ew.
> No it shouldn't, because it is not related to Perl.
> How the OS handles command line switches is related to the OS/terminal.
Hmm? In these cases argv[1] in main() is "-we" and "-ew". There is
no point where OS *could* get involved in the process.
It was Larry's decision that -e's argument does not need to be
separated by SPACE. IMO too this decision was botched; but Larry has
excuses: it was probably there already in v1.0.0, when it was not
clear how much confusion it could cause; then backward compatibility
police got established.
Hope this helps,
Ilya
------------------------------
Date: Wed, 04 Jun 2003 00:05:22 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perlrun manpage should warn that -we is a lot different than -ew
Message-Id: <nc3qdvge74vrljaoj9m1jriohin7hhn3bb@4ax.com>
On Sun, 01 Jun 2003 13:29:46 +0800, Dan Jacobson
<jidanni@dman.ddts.net> wrote:
>The perlrun manpage should warn that using -we is a lot different than -ew.
>Over and out.
If it really were so, then it should also give an analogous warning
for *every* other couple of parameters such that at least one of them
requires a mandatory argument.
No, following the above reasoning line, maybe it should give an
analogous warning for *every* finite[*] sequence of parameters such
that at least one of them requires a mandatory argument.
Better yet! Just every *nix (-like) utility supporting multiple
arguments (via getopts or a la getopts) should give an analogous
warning for every...
[*] I say "finite sequence" because there are hardly known programs
supporting *infinite* sequences of parameters on the command line. One
major noteworthy difficulty with them, anyway, is with supplying an
argument for the *last* switch!!
Michele
--
$\=q.,.,$_=q.print' ,\g,,( w,a'c'e'h,,map{$_-=qif/g/;chr
}107..q[..117,q)[map+hex,split//,join' ,2B,, w$ECDF078D3'
F9'5F3014$,$,];];$\.=$/,s,q,32,g,s,g,112,g,y,' , q,,eval;
------------------------------
Date: 3 Jun 2003 14:01:03 -0700
From: ahogue@law.berkeley.edu (Alan Hogue)
Subject: Posting to an asp form with hidden fields
Message-Id: <a35f0a7c.0306031238.7df08ec6@posting.google.com>
Hello,
I've searched all over and can't find something that quite answers my
question. My appologies if I'm mistaken.
I'm using LWP::UserAgent and HTTP::Request::Common to post to a search
form. The form is an asp page with three hidden fields and some
javascript that takes the values from three of the non-hidden fields,
processes the values, and then inserts these values into the hidden
fields. Originally I just tried posting without using the hidden
fields (since I didn't need to use the corresponding non-hidden fields
anyway), but that didn't work (got a 404 error, which is what I get no
matter what I do).
So here are the assumptions I am using: First, I assume I need to post
to the hidden fields regardless of whether anything is in them.
Further, my understanding is that, in this case, I need to post
directly to the hidden fields, rather than to the corresponding
non-hidden fields, because otherwise the JS will not pick up the
values and process them. Therefore I need to figure out what the JS is
doing to the original values and post values that are formatted the
same way.
The problem is that no matter what I try, I get the same result: a 404
(Not Found) Object Not Found error. Before I go on trying to get the
values for the hidden fields right (and pulling my hair out), I'd
appreciate it if someone could tell me whether I am even on the right
track here. First of all, are my assumptions correct? Is there some
obvious mistake in my code? Am I just not understanding the javascript
correctly?
For instance, I notice in the javascript (below) that two of the three
hidden fields don't appear to get anything passed to them at all as
long as nothing was selected in the corresponding non-hidden fields.
But wouldn't this mean, since I don't even need them, that I don't
have to post anything to them? But if I do that, I get the same exact
error, so that would make me wonder whether there is some other
problem that I need to solve. Any help would be really appreciated.
The code is below.
_________
Here is most of my code:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use HTTP::Cookies;
use strict;
use LWP::Debug '+';
my $cookie_jar = HTTP::Cookies->new(
file => 'C:\Documents and Settings\axh\My Documents\Perl
Files\nalp_grab\lwp_cookies.dat',
autosave => 1,
);
my $ua = LWP::UserAgent->new;
$ua->cookie_jar($cookie_jar);
#Pick up a session cookie by fetching the default page.
my $pre_req = POST 'http://www.nalpdirectory.com/default.asp';
my $pre_response = $ua->request($pre_req)->as_string;
#Send search parameters.
#cmbFirmType is the only field a care about
#The other three are hidden fields
my $req = POST 'http://www.nalpdirectory.com/searchresults.asp',
[ cmbFirmType => 'All',
Prac => '',
OtherPracArea => '',
CampIntv => ''
];
my $response = $ua->request($req)->as_string;
________
Result: a 404 (Not Found) Object Not Found error
_________
Here is the javascript in question. cmbPracAreas is processed and goes
into the hidden Prac field, cmbCampIntv is processed and goes into the
hidden CampIntv field, and txtOtherPracticeArea is dumped for some
reason into OtherPracArea.
function fnSubmit()
{
if(document.frmSearch.cmbPracAreas.selectedIndex > 0)
{
var PracArea = new String()
PracArea = ""
var PA = 0
for(i= 1 ; i<document.frmSearch.cmbPracAreas.options.length; i++)
{
if (document.frmSearch.cmbPracAreas.options[i].selected==true)
{
PracArea = PracArea + " upper(pracarea.practice) like upper('%" +
document.frmSearch.cmbPracAreas.options[i].value + "%') or "
PA = PA + 1
}
}
if (PA > 10)
{
window.alert("Selection of Practice Areas cannot be more than 10")
return
}
if(i > 0)
{
PracArea = PracArea.substr(0 , (PracArea.length - 4) )
}
PracArea = PracArea.toUpperCase()
document.frmSearch.Prac.value= PracArea
}
if(document.frmSearch.cmbCampIntv.selectedIndex > 0)
{
var CampInt = new String()
CampInt = ""
var CA = 0
for(i= 1 ; i<document.frmSearch.cmbCampIntv.options.length; i++)
{
if (document.frmSearch.cmbCampIntv.options[i].selected==true)
{
CampInt = CampInt + "'" +
document.frmSearch.cmbCampIntv.options[i].value + "', "
CA = CA + 1
}
}
if (CA > 10)
{
window.alert("Selection of Campus Interviews cannot be more than
10")
return
}
if(i > 0)
{
CampInt = CampInt.substr(0 , (CampInt.length - 2) )
}
CampInt = CampInt.toUpperCase()
document.frmSearch.CampIntv.value= CampInt
}
document.frmSearch.OtherPracArea.value =
document.frmSearch.txtOtherPracticeArea.value
if(document.frmSearch.cmbFirmType.selectedIndex == 0)
{
window.alert("Please Select the Firm Type from the DropDown Box")
document.frmSearch.cmbFirmType.focus()
return
}
document.frmSearch.action="searchresults.asp"
document.frmSearch.submit()
}
_____
I can also provide headers and debugging information if necessary.
Thanks very much in advance!
Alan
------------------------------
Date: 3 Jun 2003 09:39:54 -0700
From: david.pointon@tesco.net (Dave Pointon)
Subject: Reference types
Message-Id: <80fceb32.0306030839.3b1baa8@posting.google.com>
Hi all,
Can anyone help ...
I'm doing my nut trying to distinguish between references to anonymous
and named data elements i.e. given a sub which takes a reference,
can/should the sub be able to determine whether the reference is to
named or anonymous data.
Any help greatly appreciated,
TIA,
Dave P
------------------------------
Date: Tue, 3 Jun 2003 14:50:02 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Reference types
Message-Id: <slrnbdpuva.hue.tadmc@magna.augustmail.com>
Dave Pointon <david.pointon@tesco.net> wrote:
> Can anyone help ...
If we knew what the _real_ problem was we might be able to help...
> I'm doing my nut trying to distinguish between references to anonymous
> and named data elements
Why do you think that you need to distinguish them?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 03 Jun 2003 17:58:37 +0200
From: David Bouman <dbo@xbn.nl>
Subject: Re: Remove first character in a string?
Message-Id: <3EDCC5AD.E69FD3FB@xbn.nl>
Koos Pol wrote:
> chip() should make a fine opposite to chop() I find myself removing
> a first char regularly.
Nah, that would imply having an opposite to chomp() as well, and I
can't imagine anyone having *that* monkey on one's back.
--
David.
------------------------------
Date: Tue, 3 Jun 2003 14:51:58 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Remove first character in a string?
Message-Id: <slrnbdpv2u.hue.tadmc@magna.augustmail.com>
David Bouman <dbo@xbn.nl> wrote:
> Koos Pol wrote:
>
>> chip() should make a fine opposite to chop() I find myself removing
>> a first char regularly.
>
> Nah, that would imply having an opposite to chomp() as well,
sub pmohc { # the anti-chomp
$_[0] .= $/;
}
:-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 03 Jun 2003 15:01:34 -0700
From: swen <swen@news.com>
Subject: speed up loading of modules (cgi)
Message-Id: <3EDD1ABE.EA91042C@news.com>
Hi,
I have a collection of perl modules which form a framework for some of
my cgi web apps. These modules have become numerous and the amount of
code loaded (and used) on an average request has become large. The
greater the number of modules and their sizes become, the slower my apps
become. Through benchmarking different points in the initialization
(which occurs on each request), I've confirmed the module require'ing is
the big bottleneck. I'd like to eliminate the cost of the initial load
of these modules and I'm trying to decide which solution to use.
I've researched a little and there seem to be two basic avenues. One is
use a different web server (i.e. one that uses a persistent perl
process). The other is use one of the many perl modules created to solve
this problem. I'd like to investigate further the latter option.
Specifically, I'm wondering about the B module. Has anyone here had
experience using B for CGI apps? Are there any issues or limitations
with B I should be aware of? The module framework I use is almost
totally object-oriented and uses lots of inheritence and things like
AUTOLOADing.
By the way, the reason I prefer not going the mod_perl route is I want
my stuff to rely on a specific apache config as little as possible (the
system will be moving around a lot).
I'm using perl 5.6.1 and apache 1.3.22 on win2k.
Thanks for any input.
------------------------------
Date: 03 Jun 2003 21:46:45 GMT
From: Chris <devnull@pipex.com>
Subject: Unix to Win2k servers
Message-Id: <3edd1745$0$955$cc9e4d1f@news.dial.pipex.com>
I need to be able to run a command, from unix to a whole series of Win 2k
servers, and grab the output. Basically, something like the ssh mod for
unix, or TCL/expect.
Is there a module out there which I can use to authenticate to win2k using
AD, and run a cmd shell? Worst case, I'll run it from another win2k in the
same domain if neccessary, but I'd rather not.
All pointers gratefully received - I got way too many hits on CPAN for
"unix windows login", and none of them turned out to be interesting.
Cheers,
Chris.
------------------------------
Date: Tue, 3 Jun 2003 20:15:02 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Using "eval" with "my", works up to a point, then ...
Message-Id: <bbivk6$17lb$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Tassilo v. Parseval
<tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bbeof6$6nc$1@nets3.rz.RWTH-Aachen.DE>:
> > my $eval_me = ' my $a ' ;
> >
> > print $eval_me, "<-- in evalme\n" ;
> >
> > eval $eval_me ;
>
> Now you have a lexical variable $a lying around.
Nope, wrong tense. The variable had been lying around during the "time"
that eval was running the code. Not any more.
I put time in quotes because lexicality is not time-related, but
space-related. The scope starts at some *place* in the script, and
ends likewise; NOT at some moment of time.
Ilya
P.S. The solution to the particular problem is to stop using Perl
parser internal tables as a hash. Declare a lexical hash
*beforehands*, then work explicitly with the elements of this
hash - instead of using named variables.
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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 V10 Issue 5070
***************************************