[28901] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 145 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 16 14:14:23 2007

Date: Fri, 16 Feb 2007 11:14:14 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 16 Feb 2007     Volume: 11 Number: 145

Today's topics:
        Perl thread question <ecarlson@vmware.com>
    Re: Perl thread question <glex_no-spam@qwest-spam-no.invalid>
    Re: Perl thread question <thepoet_nospam@arcor.de>
        Perl:CGI - Creating a Please wait message <wjharrisiii@optonline.net>
    Re: Perl:CGI - Creating a Please wait message <glex_no-spam@qwest-spam-no.invalid>
    Re: problem reading remote file. <tadmc@augustmail.com>
    Re: problem reading remote file. <wahab-mail@gmx.de>
    Re: Regexp for email addresses. <bik.mido@tiscalinet.it>
    Re: Regexp for email addresses. <stoupa@practisoft.cz>
    Re: set a variable with a specified  element of an arra <glennj@ncf.ca>
    Re: set a variable with a specified  element of an arra <wahab-mail@gmx.de>
    Re: Uninstall a module? (Randal L. Schwartz)
    Re: Why can't I access variable from other subroutine? (Heinrich Mislik)
    Re: Why can't I access variable from other subroutine? <tadmc@augustmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 16 Feb 2007 09:19:28 -0800
From: "Eric" <ecarlson@vmware.com>
Subject: Perl thread question
Message-Id: <1171646368.619558.23000@v45g2000cwv.googlegroups.com>

Hello,

I was given a task that requires me to launch multiple executions of
the same script using different args as input. Instead of waiting for
the first to complete before starting the second one, I need to run
them in their own thread (i.e. parallel).

Here is what I've done so far. The script I am executing is called
'log_on_off.exp', which is an Expect script that logs on, then off of
a console, which is provided as input to the command:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
use Config;
use threads;

my @cmdline = ("log_on_off.exp mach003-con",
               "log_on_off.exp mach022-con",
               "log_on_off.exp mach030-con");

foreach (@cmdline) {
    my $thr = threads->new(\&runExpectScript, $_);
}

sub runExpectScript {
    my $cmd = $_;
    my $runScript = `$cmd`;
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

After running this script, I can see that all three executions are
running as separate processes, which is what I would expect:

$ ps
  PID TTY          TIME CMD
 2150 pts/1    00:00:23 bash
30151 pts/1    00:00:00 log_on_off.exp
30153 pts/1    00:00:00 log_on_off.exp
30155 pts/1    00:00:00 log_on_off.exp
30268 pts/1    00:00:00 ps
$

It turns out that I need the result of the subroutine to determine if
the login, logout was successful. So I tried using the join function
as follows:

vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
use Config;
use threads;

my @cmdline = ("log_on_off.exp mach003-con",
               "log_on_off.exp mach022-con",
               "log_on_off.exp mach030-con");

foreach (@cmdline) {
    my $thr = threads->new(\&runExpectScript, $_);
    my $retResponse = $thr->join;
}

sub runExpectScript {
    my $cmd = $_;
    my $runScript = `$cmd`;

    if ($runScript =~ m/successful/) {
        print "SUCCESS\n";
    } else {
        print "FAILURE\n";
    }
}
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When I run this Perl script in the background, I never see more than
one log_on_off.exp process running at any time. According to the
document I am using as a learning tool (http://perldoc.perl.org/
perlthrtut.html), the join function waits for the thread to exit
before continuing. I interpret this as saying that the second command
will not be started until the first returns, which defeats the purpose
of my using Perl threads to begin with, since these commands are being
executed serially (which is no different than running them in a loop
without even using Perl threads). Is my interpretation correct?

Is there any way I can execute these commands and parse the input in
their own thread instead of waiting for the previous command to
finish? Of course, if this can be done, I need to be able to determine
what thread returned what value.

Thanks in advance to all that respond.

Eric



------------------------------

Date: Fri, 16 Feb 2007 12:31:49 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl thread question
Message-Id: <45d5f872$0$702$815e3792@news.qwest.net>

Parallel::ForkManagerEric wrote:
> Hello,
> 
> I was given a task that requires me to launch multiple executions of
> the same script using different args as input. Instead of waiting for
> the first to complete before starting the second one, I need to run
> them in their own thread (i.e. parallel).

Maybe take a look at Parallel::ForkManager.


------------------------------

Date: Fri, 16 Feb 2007 20:04:12 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Perl thread question
Message-Id: <45d60023$0$6440$9b4e6d93@newsspool2.arcor-online.net>

Eric wrote:
> Hello,
> 
> I was given a task that requires me to launch multiple executions of
> the same script using different args as input. Instead of waiting for
> the first to complete before starting the second one, I need to run
> them in their own thread (i.e. parallel).
> 
[...]
> 
> It turns out that I need the result of the subroutine to determine if
> the login, logout was successful. So I tried using the join function
> as follows:
> 
> vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
> use Config;
> use threads;
> 
> my @cmdline = ("log_on_off.exp mach003-con",
>                "log_on_off.exp mach022-con",
>                "log_on_off.exp mach030-con");
> 
> foreach (@cmdline) {
>     my $thr = threads->new(\&runExpectScript, $_);
>     my $retResponse = $thr->join;
> }
> 
> sub runExpectScript {
>     my $cmd = $_;
>     my $runScript = `$cmd`;
> 
>     if ($runScript =~ m/successful/) {
>         print "SUCCESS\n";
>     } else {
>         print "FAILURE\n";
>     }
> }
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> When I run this Perl script in the background, I never see more than
> one log_on_off.exp process running at any time. According to the
> document I am using as a learning tool (http://perldoc.perl.org/
> perlthrtut.html), the join function waits for the thread to exit
> before continuing. I interpret this as saying that the second command
> will not be started until the first returns, which defeats the purpose
> of my using Perl threads to begin with, since these commands are being
> executed serially (which is no different than running them in a loop
> without even using Perl threads). Is my interpretation correct?

Yes. You're mixing up two different things here: the execution
of the threads and the collection of their results. In your example
you're in fact waiting for the result of one thread before starting
the next one and making the use of threads obsolete.

If you want to parallelise threads, you have to first start all of
them, then collect all of them, like with

my @thrdlist;

foreach( 0 .. $#cmdline )
{
	$thrdlist[$_] = threads->new( \&runExpectScript, $cmdline[$_] );
}

my @responses;

foreach( 0 .. $#cmdline )
{
	$responses[$_] = $thrdlist[$_]->join();
}

In that example the threads are all fired as quickly as Perl permits,
then the result collection loop runs until all of them are finished
and their results can be fetched.

Note that it does hardly matter in what order the threads finish, as
when one of the first threads takes longer than later ones they simply
wait in the queue until they are join()ed. So the speed loss is just
the execution time of the remaining loop iterations (fetching the
return value and destroying the thread).

> Is there any way I can execute these commands and parse the input in
> their own thread instead of waiting for the previous command to
> finish? Of course, if this can be done, I need to be able to determine
> what thread returned what value.

That threads topic can give a lot of headache, that I know from
experience, but usually things tend to be a lot simpler than one
would have thought :)

btw., I noticed that in your script you have
sub runExpectScript {
  my $cmd = $_;

You surely want to use
   my $cmd = shift;
or
   my $cmd = $_[0];
here, as it's more of an accident that $_ holds the correct value at
this point and the correct place to look for subroutine args is @_.

-Chris


------------------------------

Date: 16 Feb 2007 08:31:49 -0800
From: "Ice Man" <wjharrisiii@optonline.net>
Subject: Perl:CGI - Creating a Please wait message
Message-Id: <1171643508.592802.191680@q2g2000cwa.googlegroups.com>

I have created a CGI program which dynamically creates an HTML FORM.
This form upon submit, goes out and does some work that can take up
to
10 minutes to complete.  Once done, the called CGI provides the user
with logged results.
My goal is to provide the user with an automated GIF and a message to
please stand by while the program is out doing its work.

I have tried to first display this "Please wait ... processing your
transaction" message at the beginning of the called CGI called
program, before any work is done.  I have also tried to call an
intermediary CGI program which displays the message and calls the
working CGI in the background.

In all cases, the message is not displayed until after the CGI
working
program [which takes 10 minutes to complete] has actually completed!

I do not have a large javascript background and I would prefer to
stay
in Perl native.  Is there anything I can do here or is my only option
to learn javascripting?

Thanks,
-Bill



------------------------------

Date: Fri, 16 Feb 2007 12:25:26 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Perl:CGI - Creating a Please wait message
Message-Id: <45d5f6f3$0$25773$815e3792@news.qwest.net>

Ice Man wrote:
> I have created a CGI program which dynamically creates an HTML FORM.
> This form upon submit, goes out and does some work that can take up
> to
> 10 minutes to complete.  Once done, the called CGI provides the user
> with logged results.
> My goal is to provide the user with an automated GIF and a message to
> please stand by while the program is out doing its work.

[...]

http://www.stonehenge.com/merlyn/WebTechniques/col20.html


------------------------------

Date: Fri, 16 Feb 2007 06:04:13 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: problem reading remote file.
Message-Id: <slrnetb7dt.pqd.tadmc@tadmc30.august.net>

Mirco Wahab <wahab-mail@gmx.de> wrote:

> Under Unix, you need to have access to the
> windows box by smbclient and fiends.
                               ^^^^^^

Did you do that on purpose, or is it an (entertaining) Freudian slip?

:-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Fri, 16 Feb 2007 15:28:58 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: problem reading remote file.
Message-Id: <er4fdo$n8q$2@mlucom4.urz.uni-halle.de>

Tad McClellan wrote:
> Mirco Wahab <wahab-mail@gmx.de> wrote:
> 
>> Under Unix, you need to have access to the
>> windows box by smbclient and fiends.
>                                ^^^^^^
> 
> Did you do that on purpose, or is it an (entertaining) Freudian slip?
> 
> :-)

Ooops,

sometimes I'd really try hard to be "funny" -
but here I was just typing during a telephone
conversation with someone else ...

Sorry ;-)

M.


------------------------------

Date: Fri, 16 Feb 2007 14:05:24 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Regexp for email addresses.
Message-Id: <4rabt21v08jnet2lr7png92bhpq1dqlf8a@4ax.com>

On 15 Feb 2007 14:42:59 -0800, "cmic" <cmic@caramail.com> wrote:

>> perl -wlpe '}{$_=3D$.}{' file  # Count the number of lines.
>           ^^^^^^^^^^^^^
>
>As a Perl beginner, i'm a bit surprised to see this working. Could you
>explain why (and how) these "counter-intuitive" } and { works ? And
>how come you found out this trick ? Very very curious about this.

Let perl tell you:

  perl -MO=Deparse -wlpe '}{$_=$.}{'

Hope this sheds some light. BTW: I was very surprised too, when I
first saw it. As it happens with most of Abigail's .sig's.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


------------------------------

Date: Fri, 16 Feb 2007 17:24:56 +0100
From: "Petr Vileta" <stoupa@practisoft.cz>
Subject: Re: Regexp for email addresses.
Message-Id: <er4nad$3108$1@ns.felk.cvut.cz>

"Abigail" <abigail@abigail.be> píse v diskusním príspevku 
news:slrnetaqep.ijp.abigail@alexandra.abigail.be...
> cmic (cmic@caramail.com) wrote on MMMMCMXVI September MCMXCIII in
> <URL:news:1171579379.110397.135680@v33g2000cwv.googlegroups.com>:
> ::  Hello
> ::
> ::  On 14 fév, 22:55, Abigail <abig...@abigail.be> wrote:
> :: > use 5.9.5;   # In fact, you need the newest blead.
> :: >
> ::  ...skipped
> :: > --
> :: > perl -wlpe '}{$_=$.}{' file  # Count the number of lines.
> ::             ^^^^^^^^^^^^^
> ::
> ::  As a Perl beginner, i'm a bit surprised to see this working. Could you
> ::  explain why (and how) these "counter-intuitive" } and { works ? And
>
> See perlrun, or do a google search for it. It has been explained
> many times.
>
Can you post here some link to pages where this is explained? I have Perl 
5.6.1 and code not work for me, I haven't perldoc for 5.9.5 and google not 
accept these characters in search phrase.

Thanks a lot.

-- 

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail 
from another non-spammer site please.)




------------------------------

Date: 16 Feb 2007 14:15:47 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: set a variable with a specified  element of an array...and all elements that follows
Message-Id: <slrnetbf4j.cf3.glennj@smeagol.ncf.ca>

At 2007-02-16 03:41AM, "Mirco Wahab" wrote:
>    ...
>    my @array = qw' 1 2 3 4 5 6 7 8 9 10 '; # qn{ .. }  is missing :-/

By "qn" I assume you mean a quoted list of numbers.

Is the basic list notation so unreadable?
    @array = (1..10);
or
    @arary = (2,4,6,8,10);

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


------------------------------

Date: Fri, 16 Feb 2007 15:25:55 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: set a variable with a specified  element of an array...and all elements that follows
Message-Id: <er4f82$n8q$1@mlucom4.urz.uni-halle.de>

Glenn Jackman wrote:
> At 2007-02-16 03:41AM, "Mirco Wahab" wrote:
>>    my @array = qw' 1 2 3 4 5 6 7 8 9 10 '; # qn{ .. }  is missing :-/
> 
> By "qn" I assume you mean a quoted list of numbers.
> 
> Is the basic list notation so unreadable?
>     @array = (1..10);
> or
>     @arary = (2,4,6,8,10);

[ somwhere in germany (',' is "decimal point" all over the place) ]

     use locale;
     my @array = qn{ 3,1415  2,71828 0,57721 10^4  2^16 1+1 }

     map print "$_,\n", @array;


3.14150
2.71828
0.57721
10000
65536
2


Regards

M.


------------------------------

Date: Thu, 15 Feb 2007 14:40:29 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: "Tracey" <tlundrigan@gmail.com>
Subject: Re: Uninstall a module?
Message-Id: <86odnv2gf6.fsf@blue.stonehenge.com>

>>>>> "Tracey" == Tracey  <tlundrigan@gmail.com> writes:

Tracey> I force installed DBD::mysql when I shouldn't have and have broken
Tracey> just about everything I had running on this particular server.  I'm
Tracey> getting 'perl:relocation error' all over the place.  Any idea how I
Tracey> restore this or uninstall it and get my server back to normal?

The CPAN and CPANPLUS installers are just that... installers.  They are not
package managers, although they have a bit of dependency-chasing built in.
(And they can never be package managers, because they don't care if two
different CPAN distros both write to the same file.)

Your only safe bet is to roll back via some other mechanism, like a backup
archive.

print "Just another Perl hacker,"; 
-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
Posted via a free Usenet account from http://www.teranews.com



------------------------------

Date: 16 Feb 2007 11:31:40 GMT
From: Heinrich.Mislik@univie.ac.at (Heinrich Mislik)
Subject: Re: Why can't I access variable from other subroutine?
Message-Id: <45d5961b$0$12384$3b214f66@usenet.univie.ac.at>

In article <DbGdnUWsuf6Qs0jYnZ2dnUVZ_syunZ2d@comcast.com>, itfred@cdw.com says...
>
>
>The two subs below are in a package named Mypkg.pm.
>The LoadConfig sub uses AppConfig.  In this sub I
>can print the host variable using $config->host().
>So I added the line our $hostx = $config->host(),
>to assign this to $hostx.  Now in the TestSub sub,
>I try and print Mypkg::LoadConfig::hostx, but it
>never prints.  How can I access hostx from the
>TestSub subroutine?
>
>-Thanks
>
>
>sub LoadConfig
>{
>  shift @_;
>  my ($cfgfile, $prn) = @_;
>  my $config = '';
>
>  $config = AppConfig->new(
>    {
>     CASE   => 1,
>     PEDANTIC => 0,
>     CREATE => 1,
>     ERROR => sub {},
>     GLOBAL => { ARGCOUNT => ARGCOUNT_ONE }
>    }
>  ); 
>
>  $config->file($cfgfile);
>
>
>  ####### Can't access this below in DBConnect ########
>  our $hostx = $config->host();
>
>
>  if ($prn eq 'p') {
>    print "Configuration file: $cfgfile\n";
>    print  "dbname:\t\t".$config->dbname()."\n";
>    print  "host:\t\t".$config->host()."\n";
>    print  "port:\t\t".$config->port()."\n";
>    print  "username:\t".$config->username()."\n";
>  }
>
>}
>
>
>sub TestSub
>{
>
>  LoadConfig('/etc/my.conf');
>
>  ######## Cannot print host variable from LoadConfig above ########
>  print Mypkg::LoadConfig::hostx;
   
   print $Mypkg::hostx,"\n";

>
>}

greetings

Heinrich Mislik



------------------------------

Date: Fri, 16 Feb 2007 06:00:19 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Why can't I access variable from other subroutine?
Message-Id: <slrnetb76j.pqd.tadmc@tadmc30.august.net>

Jürgen Exner <jurgenex@hotmail.com> wrote:
> Fred wrote:
>> The two subs below are in a package named Mypkg.pm.
>> The LoadConfig sub uses AppConfig.  In this sub I
>> can print the host variable using $config->host().
>> So I added the line our $hostx = $config->host(),
>> to assign this to $hostx.  >
>> sub LoadConfig
> [...]
>>  our $hostx = $config->host();
>
> The "our" makes this a variable that is visible only within the sub 
> LoadConfig()


No, it makes the short name ($hostx) visible only within the (sub) block.

The long name ($Some::Package::hostx) can still be used to access
that variable.


> Make $hostx a global variable.


It already is a package (global) variable.

our() does not scope variables, it only scopes a _name_
for the variable.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

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 145
**************************************


home help back first fref pref prev next nref lref last post