[30580] in Perl-Users-Digest
Perl-Users Digest, Issue: 1823 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 27 18:10:15 2008
Date: Wed, 27 Aug 2008 15:09: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 Wed, 27 Aug 2008 Volume: 11 Number: 1823
Today's topics:
Re: Converting the text output to excel via perl. <woland99@gmail.com>
Re: Huge perl scripts collection of any kinds for free <1usa@llenroc.ude.invalid>
perl multithreading performance dniq00@gmail.com
Re: perl multithreading performance <fawaka@gmail.com>
Re: perl multithreading performance <tzz@lifelogs.com>
Re: perl multithreading performance dniq00@gmail.com
Re: perl multithreading performance dniq00@gmail.com
Re: perl multithreading performance <m@rtij.nl.invlalid>
Question in Perl leejinhoo@gmail.com
Re: Question in Perl <magloca@mailinater.com>
Re: Question in Perl leejinhoo@gmail.com
Re: Question in Perl <bugbear@trim_papermule.co.uk_trim>
Re: Question in Perl leejinhoo@gmail.com
Re: Question in Perl <jurgenex@hotmail.com>
Re: Question in Perl <bugbear@trim_papermule.co.uk_trim>
Re: Question in Perl <spamtrap@dot-app.org>
Re: Question in Perl <cartercc@gmail.com>
Re: Repeating the loop <jurgenex@hotmail.com>
Re: subprocesses lifecycle <ced@blv-sam-01.ca.boeing.com>
Truncate an array when you have a ref to it? <Alexander.Farber@gmail.com>
Re: Truncate an array when you have a ref to it? <someone@example.com>
Re: Truncate an array when you have a ref to it? <tzz@lifelogs.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Aug 2008 14:51:19 -0700 (PDT)
From: Woland99 <woland99@gmail.com>
Subject: Re: Converting the text output to excel via perl.
Message-Id: <9737bb67-438c-4fea-8794-8e84b5ec7330@s50g2000hsb.googlegroups.com>
On Aug 25, 2:10 am, Sana <scripts...@gmail.com> wrote:
> I have the following output which I want to convert intoexcel...Any
> pointers how to achieve it via Spreadsheet::WriteExcel;
>
> I am a beginer so pardon my lack of knowledge in perl.
>
> lpar_name minmem desmem maxmem minpr despr maxpr
> commuq21 2048 8192 12288 0.1 1.0 2.0
> commuq20 2048 8192 12288 0.1 1.0 2.0
> commuq23 2048 16384 40960 0.1 2.0 4.0
> commud18 3072 40960 61440 0.2 2.0 5.0
> commup03 2048 24576 30720 0.1 3.0 4.0
> commup02 10240 32768 32768 1.0 4.0 8.0
> commup01 10240 32768 32768 1.0 4.0 8.0
>
> Regards
> Sana
I use Win32::OLE - try sth like this (edited version of my
own code may not work out of the box - for better examples
check Win32::OLE docs)
------------------------------------------
#for OLE automation
use Win32::OLE;
use Win32::OLE::Const "Microsoft Excel";
use Win32::OLE 'in';
use Win32::OLE::Variant;
#get current directory
use Cwd;
use strict;
my $excel;
#--------------------------------------------------------------------------------------
#writes array of array references as new excel spreadsheet
sub write_array_as_excel_file
{
#-------------------------------------------------------------------
#1st is name of output file
my $output_file = shift;
#2nd argument is assumes as refrence to array of array references
#each array references contains values for the whole row in
spreadsheet
my $array_ref = shift;
#-------------------------------------------------------------------
my $dir = cwd();
my $fullname_output_file = $dir.'/'.$output_file;
# use existing instance if Excel is already running
eval
{
$excel = Win32::OLE->GetActiveObject('Excel.Application')
};
die "Excel not installed" if $@;
unless (defined $excel)
{
$excel = Win32::OLE->new('Excel.Application', 'Quit')
or die "Oops, cannot start Excel";
}
#to avoid excessive dialogs when saving in non-Excel format
$excel->{DisplayAlerts} = 0;
# get a new workbook
my $wbook = $excel->Workbooks->Add
|| print STDERR "didnt add new workbook: $!\n";
# write to a particular cell
my $wsheet = $wbook->Worksheets(1);
my $ref;
my $cell_value;
my $row_num = scalar @{$array_ref};
my $col_num = scalar @{$array_ref->[0]};
$wsheet->Range($wsheet->Cells(1,1), $wsheet->Cells($row_num,
$col_num) )->{Value} = $array_ref;
$wbook->SaveAs($fullname_output_file);
$wbook->Close();
}
------------------------------
Date: Wed, 27 Aug 2008 11:19:34 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Huge perl scripts collection of any kinds for free
Message-Id: <Xns9B074A7FAEBE1asu1cornelledu@127.0.0.1>
cmic <cmic@caramail.com> wrote in
news:c47982a9-d2c2-4481-a361-e646c5cb46b6@l42g2000hsc.googlegroups.com:
> On 27 août, 02:24, Albertos <lfrogerscob...@gmail.com> wrote:
>> Hello, I've collected huge perl scripts collection of any kinds :
>> work with text files, database, GUI etc. You can download it
>> herehttp://freact
> or.com/get.php?file=perl+scripts
>
> Please stop sending insane spyware in this newgroup. Try alt.sex or
> other garbage group
Please do not respond to people who send links to spyware. These people
don't read the responses to their posts.
Productive things you can do include reporting the post to Google and
Ukraine Telecom.
> --
> cmic, perl user/fan/etc..
The format of your signature separator is incorrect. It should be dash
dash space newline. Yours is missing the space.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)
comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
------------------------------
Date: Wed, 27 Aug 2008 12:59:36 -0700 (PDT)
From: dniq00@gmail.com
Subject: perl multithreading performance
Message-Id: <ce5b0a68-14f6-4296-94da-8edfca898e77@j22g2000hsf.googlegroups.com>
Hello, oh almighty perl gurus!
I'm trying to implement multithreaded processing for the humongous
amount of logs that I'm currently processing in 1 process on a 4-CPU
server.
What the script does is for each line it checks if the line contains
GET request, and if it does - goes through a list of pre-compiled
regular expressions, trying to find a matching one. Once the match is
found - it uses another regexp, associated with the found match, which
is a bit more complex, to extract data from the line. I have split it
in two separate matches, because about 30% of all lines will match,
and I don't want to run that complex regexp to extract data for all
the lines I know won't match. The goal is to count how many lines
matched for every specific regexp, and the end result is built as a
hash, having data, extracted from the line with second regexp, used as
hash keys, and the value is the number of matches.
Anyway, currently all this is done in a single process, which parses
approx. 30000 lines per second. The CPU usage for this process is
100%, so the bottleneck is in the parsing part.
I have changed the script to use threads + threads::shared +
Thread::Queue. I read data from logs like this:
Code
until( $no_more_data ) {
my @buffer;
foreach( (1..$buffer_size) ) {
if( my $line = <> ) {
push( @buffer, $line );
} else {
$no_more_data = 1;
$q_in->enqueue( \@buffer );
foreach( (1..$cpu_count) ) {
$q_in->enqueue( undef );
}
last;
}
}
$q_in->enqueue( \@buffer ) unless $no_more_data;
}
Then, I create $cpu_count threads, which does something like this:
Code
sub parser {
my $counters = {};
while( my $buffer = $q_in->dequeue() ) {
foreach my $line ( @{ $buffer } ) {
# do its thing
}
}
return $counters;
}
Everything works fine, HOWEVER! It's all so damn slow! It's only 10%
faster than single-process script, consumes about 2-3 times more
memory and about as much times more CPU.
I've also tried abandoning the Thread:Queue and just use
threads::shared with lock/cond_wait/cond_signal combination, without
much success.
I've tried to play with $cpu_count and $buf_size, and found that after
$buf_size > 1000 doesn't make much difference, and $cpu_count > 2
actually makes things a lot worse.
Any ideas why in the world it's so slow? I did some research and
couldn't find a lot of info, other than the way I do it pretty much
the way it should be done, unless I'm missing something...
Hope anybody can enlighten me...
THANKS!
------------------------------
Date: 27 Aug 2008 20:39:53 GMT
From: Leon Timmermans <fawaka@gmail.com>
Subject: Re: perl multithreading performance
Message-Id: <48b5bb99$0$192$e4fe514c@news.xs4all.nl>
On Wed, 27 Aug 2008 12:59:36 -0700, dniq00 wrote:
>
> Everything works fine, HOWEVER! It's all so damn slow! It's only 10%
> faster than single-process script, consumes about 2-3 times more memory
> and about as much times more CPU.
>
> I've also tried abandoning the Thread:Queue and just use threads::shared
> with lock/cond_wait/cond_signal combination, without much success.
>
> I've tried to play with $cpu_count and $buf_size, and found that after
> $buf_size > 1000 doesn't make much difference, and $cpu_count > 2
> actually makes things a lot worse.
>
> Any ideas why in the world it's so slow? I did some research and
> couldn't find a lot of info, other than the way I do it pretty much the
> way it should be done, unless I'm missing something...
>
> Hope anybody can enlighten me...
>
> THANKS!
The speed of perl's threading is dependent on how much you share between
threads. Sharing the lines before processing them can become a
bottleneck, I suspect that's the problem in your case. You probably want
to divide the work first, and only used shared resources to report back
the results. Making a program scale over multiple processors isn't easy.
Sean O'Rourke entry in the wide finder benchmark (http://www.cs.ucsd.edu/
~sorourke/wf.pl) offers an interesting approach to this, though it isn't
exactly optimized for readability.
Regards,
Leon Timmermans
------------------------------
Date: Wed, 27 Aug 2008 16:06:37 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: perl multithreading performance
Message-Id: <86prnugobm.fsf@lifelogs.com>
On Wed, 27 Aug 2008 12:59:36 -0700 (PDT) dniq00@gmail.com wrote:
d> What the script does is for each line it checks if the line contains
d> GET request, and if it does - goes through a list of pre-compiled
d> regular expressions, trying to find a matching one. Once the match is
d> found - it uses another regexp, associated with the found match, which
d> is a bit more complex, to extract data from the line. I have split it
d> in two separate matches, because about 30% of all lines will match,
d> and I don't want to run that complex regexp to extract data for all
d> the lines I know won't match. The goal is to count how many lines
d> matched for every specific regexp, and the end result is built as a
d> hash, having data, extracted from the line with second regexp, used as
d> hash keys, and the value is the number of matches.
d> Anyway, currently all this is done in a single process, which parses
d> approx. 30000 lines per second. The CPU usage for this process is
d> 100%, so the bottleneck is in the parsing part.
...
d> Everything works fine, HOWEVER! It's all so damn slow! It's only 10%
d> faster than single-process script, consumes about 2-3 times more
d> memory and about as much times more CPU.
...
d> Any ideas why in the world it's so slow? I did some research and
d> couldn't find a lot of info, other than the way I do it pretty much
d> the way it should be done, unless I'm missing something...
You may be hitting the limits of I/O. Try feeding your script
pre-canned data from memory in a loop and see if that improves
performance. It also depends on what kind of processing you are doing
on input lines.
Also, check out the swatch log file monitor, it may do what you need
already.
Ted
------------------------------
Date: Wed, 27 Aug 2008 14:15:34 -0700 (PDT)
From: dniq00@gmail.com
Subject: Re: perl multithreading performance
Message-Id: <d8189789-abe5-4460-919a-7b6fe57b2919@79g2000hsk.googlegroups.com>
On Aug 27, 5:06=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> You may be hitting the limits of I/O. =A0Try feeding your script
> pre-canned data from memory in a loop and see if that improves
> performance.
No, the IO is fine - there are pretty much always $q_in->pending > 1,
and as the script does its thing, number of pending buffers sometimes
goes beyond 10.
>=A0It also depends on what kind of processing you are doing
> on input lines.
Just trying to match multiple regexps against each line.
> Also, check out the swatch log file monitor, it may do what you need
> already.
Nope, it doesn't :( I already have the single-threaded script, which
has been working for years now, but the amount of logs it needs to
process keeps growing, and I'm basically at the point where it can
only keep up with the speed with which logs are being written, so if
there's back-log for whatever reason - it might not catch up, so I'm
looking into how I can improve its performance.
------------------------------
Date: Wed, 27 Aug 2008 14:25:32 -0700 (PDT)
From: dniq00@gmail.com
Subject: Re: perl multithreading performance
Message-Id: <df4a5a0c-9ff8-4403-bb2e-a5eb995c5f40@j22g2000hsf.googlegroups.com>
On Aug 27, 4:39=A0pm, Leon Timmermans <faw...@gmail.com> wrote:
> On Wed, 27 Aug 2008 12:59:36 -0700, dniq00 wrote:
>
> > Everything works fine, HOWEVER! It's all so damn slow! It's only 10%
> > faster than single-process script, consumes about 2-3 times more memory
> > and about as much times more CPU.
>
> > I've also tried abandoning the Thread:Queue and just use threads::share=
d
> > with lock/cond_wait/cond_signal combination, without much success.
>
> > I've tried to play with $cpu_count and $buf_size, and found that after
> > $buf_size > 1000 doesn't make much difference, and $cpu_count > 2
> > actually makes things a lot worse.
>
> > Any ideas why in the world it's so slow? I did some research and
> > couldn't find a lot of info, other than the way I do it pretty much the
> > way it should be done, unless I'm missing something...
>
> > Hope anybody can enlighten me...
>
> > THANKS!
>
> The speed of perl's threading is dependent on how much you share between
> threads. Sharing the lines before processing them can become a
> bottleneck, I suspect that's the problem in your case. You probably want
> to divide the work first, and only used shared resources to report back
> the results. Making a program scale over multiple processors isn't easy.
> Sean O'Rourke entry in the wide finder benchmark (http://www.cs.ucsd.edu/
> ~sorourke/wf.pl) offers an interesting approach to this, though it isn't
> exactly optimized for readability.
>
> Regards,
>
> Leon Timmermans
Thanks for the link - trying to figure out whattahellisgoingon
there :) Looks like he's basically mmaps the input and begins reading
it starting at different points. Thing is, I'm using <> as input,
which can contain hundreds of gigabytes of data, so I'm not sure how's
that going to work out...
------------------------------
Date: Wed, 27 Aug 2008 23:53:09 +0200
From: Martijn Lievaart <m@rtij.nl.invlalid>
Subject: Re: perl multithreading performance
Message-Id: <pan.2008.08.27.21.53.09@rtij.nl.invlalid>
On Wed, 27 Aug 2008 14:15:34 -0700, dniq00 wrote:
> Nope, it doesn't :( I already have the single-threaded script, which has
> been working for years now, but the amount of logs it needs to process
> keeps growing, and I'm basically at the point where it can only keep up
> with the speed with which logs are being written, so if there's back-log
> for whatever reason - it might not catch up, so I'm looking into how I
> can improve its performance.
Perl threading, well frankly, sucks. You may want to switch to another
language with re support that meets your needs. I would go for C++ (with
boost), but then I know that language very well.
M4
------------------------------
Date: Wed, 27 Aug 2008 06:40:53 -0700 (PDT)
From: leejinhoo@gmail.com
Subject: Question in Perl
Message-Id: <bee6ded0-7361-426c-8bfa-472135089f88@z72g2000hsb.googlegroups.com>
Hi All,
I am learning how to use Perl. When I was first time using VBA, I
could use "F8" to track how all the variables change each by each and
step by step so that I can understand how the coding flows. Is there
any method to do so (or similar) in Perl? Many thanks!
Best regards,
Ronald
------------------------------
Date: Wed, 27 Aug 2008 16:02:57 +0200
From: magloca <magloca@mailinater.com>
Subject: Re: Question in Perl
Message-Id: <48b55e91$0$4245$6e1ede2f@read.cnntp.org>
leejinhoo@gmail.com @ Wednesday 27 August 2008 15:40:
> I am learning how to use Perl. When I was first time using VBA, I
> could use "F8" to track how all the variables change each by each and
> step by step so that I can understand how the coding flows. Is there
> any method to do so (or similar) in Perl? Many thanks!
See 'perldoc perldebug', for command-line debugging, or
http://www.activestate.com/Products/komodo_ide/ for the graphical
development environment Komodo (which costs money and which I
personally know nothing about other than its name).
m.
------------------------------
Date: Wed, 27 Aug 2008 07:22:47 -0700 (PDT)
From: leejinhoo@gmail.com
Subject: Re: Question in Perl
Message-Id: <60f5517c-90b8-4a42-acea-38bf27124567@l64g2000hse.googlegroups.com>
Thanks! m
Where can I find "perldoc perldebug"? I keep searching them but cannot
find them. Thanks!
On Aug 27, 10:02=A0am, magloca <magl...@mailinater.com> wrote:
> leejin...@gmail.com @ Wednesday 27 August 2008 15:40:
>
> > I am learning how to use Perl. When I was first time using VBA, I
> > could use "F8" to track how all the variables change each by each and
> > step by step so that I can understand how the coding flows. Is there
> > any method to do so (or similar) in Perl? Many thanks!
>
> See 'perldoc perldebug', for command-line debugging, orhttp://www.actives=
tate.com/Products/komodo_ide/for the graphical
> development environment Komodo (which costs money and which I
> personally know nothing about other than its name).
>
> m.
------------------------------
Date: Wed, 27 Aug 2008 15:27:04 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Question in Perl
Message-Id: <9MidnZ_0X-yl-SjVnZ2dnUVZ8tDinZ2d@posted.plusnet>
leejinhoo@gmail.com wrote:
> Thanks! m
>
> Where can I find "perldoc perldebug"? I keep searching them but cannot
> find them. Thanks!
just type it on your command line.
BugBear
------------------------------
Date: Wed, 27 Aug 2008 07:47:54 -0700 (PDT)
From: leejinhoo@gmail.com
Subject: Re: Question in Perl
Message-Id: <4348bb06-0689-49cc-bc54-505dc029d577@34g2000hsh.googlegroups.com>
On Aug 27, 10:27=A0am, bugbear <bugbear@trim_papermule.co.uk_trim>
wrote:
> leejin...@gmail.com wrote:
> > Thanks! m
>
> > Where can I find "perldoc perldebug"? I keep searching them but cannot
> > find them. Thanks!
>
> just type it on your command line.
>
> =A0 =A0BugBear
Thanks a lot!
Is there any "Help" function that I can use to search for explanations
for variables? Thanks!
------------------------------
Date: Wed, 27 Aug 2008 16:02:32 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Question in Perl
Message-Id: <4guab4p0su2fuj0qtjuvidtjn05httpk1v@4ax.com>
leejinhoo@gmail.com wrote:
>On Aug 27, 10:27 am, bugbear <bugbear@trim_papermule.co.uk_trim>
>wrote:
>> leejin...@gmail.com wrote:
>> > Where can I find "perldoc perldebug"? I keep searching them but cannot
>> > find them. Thanks!
>>
>> just type it on your command line.
>
>Is there any "Help" function that I can use to search for explanations
>for variables?
See 'perldoc perlvar':
NAME
perlvar - Perl predefined variables
jue
------------------------------
Date: Wed, 27 Aug 2008 17:07:56 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Question in Perl
Message-Id: <tY2dnThBselA5ijVnZ2dnUVZ8trinZ2d@posted.plusnet>
Jürgen Exner wrote:
> leejinhoo@gmail.com wrote:
>> On Aug 27, 10:27 am, bugbear <bugbear@trim_papermule.co.uk_trim>
>> wrote:
>>> leejin...@gmail.com wrote:
>>>> Where can I find "perldoc perldebug"? I keep searching them but cannot
>>>> find them. Thanks!
>>> just type it on your command line.
>> Is there any "Help" function that I can use to search for explanations
>> for variables?
>
> See 'perldoc perlvar':
>
> NAME
> perlvar - Perl predefined variables
>
And probably 'perldoc perldoc'
:-)
BugBear
------------------------------
Date: Wed, 27 Aug 2008 13:09:50 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Question in Perl
Message-Id: <m1wsi275b5.fsf@dot-app.org>
bugbear <bugbear@trim_papermule.co.uk_trim> writes:
> Jürgen Exner wrote:
>> leejinhoo@gmail.com wrote:
>>> On Aug 27, 10:27 am, bugbear <bugbear@trim_papermule.co.uk_trim>
>>> wrote:
>>>> leejin...@gmail.com wrote:
>>>>> Where can I find "perldoc perldebug"? I keep searching them but cannot
>>>>> find them. Thanks!
>>>> just type it on your command line.
>>> Is there any "Help" function that I can use to search for explanations
>>> for variables?
>>
>> See 'perldoc perlvar':
>>
>> NAME
>> perlvar - Perl predefined variables
>>
>
> And probably 'perldoc perldoc'
>
> :-)
And, of course, "perldoc perl" for a list of all the available docs.
Also note that, if you're using ActiveState's Perl on Windows, there
are (or were, when I last looked - it's been a while) links to the
included docs in the Start menu.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Wed, 27 Aug 2008 11:05:07 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: Question in Perl
Message-Id: <961cfd8a-8b61-40f7-93af-9a1e5c99fdf8@r66g2000hsg.googlegroups.com>
On Aug 27, 9:40=A0am, leejin...@gmail.com wrote:
> Hi All,
>
> I am learning how to use Perl. When I was first time using VBA, I
> could use "F8" to track how all the variables change each by each and
> step by step so that I can understand how the coding flows. Is there
> any method to do so (or similar) in Perl? Many thanks!
There isn't a dedicated Perl IDE, like VS for VB or C#, or NetBeans
(or Eclipse or BlueJ or JGrasp or JBuilder, etc) for Java, or LispBox
for Lisp. Unless you buy a an IDE (like the Active State product)
you've got to use a text editor and the key chords and function key
mappings are determined by the editor, not by Perl.
On a Windows machine, I use Textpad, Notepad, Winvi, or even edit to
create the source files and run the scripts at the command prompt. On
a Unix/Linix machine, I use vi or emacs to create the files and run
them at the command prompt.
You can run the built in Perl debugger with the -d switch. If you
invoke the debugger, it will allow you to step through the code and
look at your variables.
CC
------------------------------
Date: Wed, 27 Aug 2008 11:18:01 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Repeating the loop
Message-Id: <8mdab4tb7cqnrmb0b9618r15j8lem1j6qo@4ax.com>
Arun <sajapuram.arun.prakash@gmail.com> wrote:
>i wanted the followinf loop to be repeated for every 30 seconds.
Didn't you ask exactly the same question in a different thread on the
20th already?
>$send_data = strftime( "::DATA::123456789101112,%d.%m.%Y,%H:%M:%S,
>13.0076367,77.5489267,0,933.4,AirTel,31,0 \n", gmtime);
>
>DATA: {while(1)
> {
> $handle-> send($send_data);
> last DATA;
> }
> }
>
>
>so how do i do it.
As you have been told before: perldoc -f sleep
jue
------------------------------
Date: Wed, 27 Aug 2008 04:32:13 -0700 (PDT)
From: "C.DeRykus" <ced@blv-sam-01.ca.boeing.com>
Subject: Re: subprocesses lifecycle
Message-Id: <05821ada-46f0-4e7b-b326-9ea69d2b057e@a8g2000prf.googlegroups.com>
On Aug 27, 1:41 am, Matthieu Imbert <bre...@remove.this.gmail.com>
wrote:
> hi.
>
> I have a perl script that forks several subprocesses at various times.
>
> I use the open "process_name |" syntax, and then use select to read
> multiple process outputs, and have a timeout on all these subprocesses.
>
> If the timeout is reached, I want to immediately exit my script with an
> error message.
>
> Currently, when I detect the timeout, I call die "error message". the
> message is displayed, but the script does not return until subprocesses
> finish (this may take several minutes, depending on what the
> subprocesses do).
>
> Is there a way to force the end of all subprocesses when calling die?
>
Each successful pipe open will return the child process id. So,
assuming a Unix O/S, you could save child id's and then send the
signal 'TERM' serially to each child id when there's a timeout, eg,
foreach my $child (@pids) {
kill 'TERM', $child
or kill 'KILL',$child
or warn "can't signal $child\n";
}
Alternatively, 'perldoc perlipc' demo's an idiom using a negative
process id to signal an entire Unix process group, eg,
{
local $SIG{TERM} = 'IGNORE';
kill TERM => -$$;
}
--
Charles DeRykus
------------------------------
Date: Wed, 27 Aug 2008 13:34:00 -0700 (PDT)
From: "A. Farber" <Alexander.Farber@gmail.com>
Subject: Truncate an array when you have a ref to it?
Message-Id: <fbdf965d-f41a-4f0c-a3e1-e1ba74b868e2@c65g2000hsa.googlegroups.com>
Hello,
I have an object representing a player:
sub new {
my $package = shift;
my $self = {
......
CHAT => [[], [], []],
};
bless($self, $package);
}
and its CHAT member holds messages
from 3 other players in an array of 3 arrays.
Then I have a method which sends those
messages over a socket to the player:
$aref = $self->{CHAT}->[0];
push @response, 'chat0=' . join '', @$aref;
$self->{CHAT}->[0] = [];
The last line truncates the sub-array
(after the messages have been sent).
I wonder if I can truncate that array by
using the $aref ? Something like $#xxxx = -1;
Thank you
Alex
------------------------------
Date: Wed, 27 Aug 2008 20:44:28 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Truncate an array when you have a ref to it?
Message-Id: <M0jtk.226597$gc5.83887@pd7urf2no>
A. Farber wrote:
> Hello,
>
> I have an object representing a player:
>
> sub new {
> my $package = shift;
> my $self = {
> ......
> CHAT => [[], [], []],
> };
> bless($self, $package);
> }
>
> and its CHAT member holds messages
> from 3 other players in an array of 3 arrays.
>
> Then I have a method which sends those
> messages over a socket to the player:
>
> $aref = $self->{CHAT}->[0];
> push @response, 'chat0=' . join '', @$aref;
> $self->{CHAT}->[0] = [];
>
> The last line truncates the sub-array
> (after the messages have been sent).
>
> I wonder if I can truncate that array by
> using the $aref ? Something like $#xxxx = -1;
Yes you could do that:
$#$aref = -1;
Or:
@$aref = ();
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Wed, 27 Aug 2008 16:01:01 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Truncate an array when you have a ref to it?
Message-Id: <86tzd6goky.fsf@lifelogs.com>
On Wed, 27 Aug 2008 13:34:00 -0700 (PDT) "A. Farber" <Alexander.Farber@gmail.com> wrote:
AF> $aref = $self->{CHAT}->[0];
AF> push @response, 'chat0=' . join '', @$aref;
AF> $self->{CHAT}->[0] = [];
AF> The last line truncates the sub-array
AF> (after the messages have been sent).
Actually it assigns a new value to that reference. The old array still
exists with the full contents if you have another reference to it (check
$aref, for instance).
AF> I wonder if I can truncate that array by
AF> using the $aref ? Something like $#xxxx = -1;
Sure:
@$aref = ();
or, equivalently,
@{$self->{CHAT}->[0]} = ();
Ted
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 V11 Issue 1823
***************************************