Re: Perl thread question
- From: Christian Winter <thepoet_nospam@xxxxxxxx>
- Date: Fri, 16 Feb 2007 21:29:40 +0100
Eric wrote:
[fire-first-collect-later code snipped]
PID TTY TIME CMD
2150 pts/1 00:00:24 bash
4194 pts/1 00:00:00 m.pl
4196 pts/1 00:00:00 log_on_off.exp
4237 pts/1 00:00:00 log_on_off.exp
4278 pts/1 00:00:00 log_on_off.exp
4316 pts/1 00:00:00 ps
Value of $t is: 140820824
SUCCESS: log_on_off.exp pdp003 pdp003-ilo
Value of $t is: 141287696
SUCCESS: log_on_off.exp osdc-pdp030 osdc-pdp030-ilo
SUCCESS: log_on_off.exp pdp022 pdp022-ilo
Value of $t is: 141228056
[ecarlson@ecarlson-dev1 remboot]$
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
As you can see, it appears that the processes are all started and
running as separate processes, as I would expect. The results are not
given in any particular order (which is ok), but appear to be
associated with the correct process based on command line. (I tried
some failure conditions and found that they match up.) The main
difference between my and your approach is that you went to extra
effort to identify each process by a number, which is probably a more
sure way than what I did. Do you feel that my approach will work
despite the fact that I didn't do this?
If you're only going for some lines of text to the screen, I don't
see why not. Though you could also return a more complex data
structure that holds both the task identification and the result and
avoid the counter this way - like always, TMTOWTDI[1] - if you
want to work on the results some more later on in your script.
But I see in your code that you're still using $_ in the subroutine
and laying out traps for yourself (and I admit not being completely
clean there with my own example). Especially with threads, where
things may happen in random order, it's always wise to keep from
$_ as far as possible. Shift into variables in the sub, and use a
named iterator in the loops, like
foreach my $count ( 0 .. $#cmdline ) {
do_something_with( $count );
}
or
foreach my $nextcommand ( @commandline ) {
do_something_with( $nextcommand );
}
or tracing back random errors may become a hell of a job once the
projects get a bit more complex.
-Chris
1) There's More Than One Way To Do It, the Perl(5?) philosophy.
.
- Follow-Ups:
- Re: Perl thread question
- From: Eric
- Re: Perl thread question
- References:
- Perl thread question
- From: Eric
- Re: Perl thread question
- From: Christian Winter
- Re: Perl thread question
- From: Eric
- Perl thread question
- Prev by Date: FAQ 4.66 How can I make my hash remember the order I put elements into it?
- Next by Date: Re: Sending a local attachment via email form
- Previous by thread: Re: Perl thread question
- Next by thread: Re: Perl thread question
- Index(es):
Relevant Pages
|