[30226] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1469 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 22 17:22:48 2008

Date: Tue, 22 Apr 2008 14:22:39 -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, 22 Apr 2008     Volume: 11 Number: 1469

Today's topics:
        Thread alternative for multi-processing? <howachen@gmail.com>
    Re: Thread alternative for multi-processing? <peter@makholm.net>
    Re: Thread alternative for multi-processing? <simon.chao@fmr.com>
    Re: Thread alternative for multi-processing? <peter@makholm.net>
    Re: Thread alternative for multi-processing? <simon.chao@fmr.com>
    Re: Thread alternative for multi-processing? xhoster@gmail.com
    Re: To find a quick way to list all files in the direct <benkasminbullock@gmail.com>
    Re: To find a quick way to list all files in the direct <benkasminbullock@gmail.com>
        Trouble  initializing multidimensional array <davewu922@gmail.com>
    Re: Trouble  initializing multidimensional array <glex_no-spam@qwest-spam-no.invalid>
    Re: Trouble  initializing multidimensional array <spamtrap@dot-app.org>
    Re: Trouble initializing multidimensional array <simon.chao@fmr.com>
    Re: Trouble initializing multidimensional array <davewu922@gmail.com>
    Re: Trouble initializing multidimensional array <glex_no-spam@qwest-spam-no.invalid>
    Re: Trouble initializing multidimensional array <kkeller-usenet@wombat.san-francisco.ca.us>
        Trying to fetch Basic Auth header in Mason <SteveSpamTrap@yahoo.com>
        uninitialized value in multidimensional array <davewu922@gmail.com>
    Re: uninitialized value in multidimensional array <RedGrittyBrick@SpamWeary.foo>
    Re: uninitialized value in multidimensional array <spamtrap@dot-app.org>
    Re: uninitialized value in multidimensional array <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 16 Apr 2008 01:44:09 -0700 (PDT)
From: howa <howachen@gmail.com>
Subject: Thread alternative for multi-processing?
Message-Id: <28460650-4163-4297-9ca0-08c14bf6e0ce@s13g2000prd.googlegroups.com>

Sometimes, I want to take the advantage of multi-core processor, and
make the full use of my CPU time,

e.g. I have a function, which takes a file name as input, do some text
processing (e.g. CPU intensive), and save it back.

I don't want to use thread, as it need to recompile perl on all my
machines and I am not sure if it is stable enough to affect other
apps.

I don't mind to have a little overhead in using the fork mode (i.e.
multi-process). I want to know are there  any recommended module for
my purpose?

For example, I am trying Parallel::ForkManager, POE::Wheel::Run, so
anyone want to share the experiences?


Thanks.


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

Date: Wed, 16 Apr 2008 08:50:06 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Thread alternative for multi-processing?
Message-Id: <87od8ambep.fsf@hacking.dk>

howa <howachen@gmail.com> writes:

> For example, I am trying Parallel::ForkManager, POE::Wheel::Run, so
> anyone want to share the experiences?

I have used Parallel::ForkManager a lot with no problems, it just
works. I have never had the need to communicate enything more complex
than the exit code back to the parrent though.

//Makholm


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

Date: Wed, 16 Apr 2008 08:03:36 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Thread alternative for multi-processing?
Message-Id: <b82727e7-c25d-4810-a675-cddd80739010@c65g2000hsa.googlegroups.com>

On Apr 16, 4:50=A0am, Peter Makholm <pe...@makholm.net> wrote:
> howa <howac...@gmail.com> writes:
> > For example, I am trying Parallel::ForkManager, POE::Wheel::Run, so
> > anyone want to share the experiences?
>
> I have used Parallel::ForkManager a lot with no problems, it just
> works. I have never had the need to communicate enything more complex
> than the exit code back to the parrent though.

I've found it useful to pass an $ident which i can use in the
run_on_finish callback to associate with the exit code.


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

Date: Wed, 16 Apr 2008 15:10:32 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Thread alternative for multi-processing?
Message-Id: <87k5ixn8d3.fsf@hacking.dk>

nolo contendere <simon.chao@fmr.com> writes:

>> I have used Parallel::ForkManager a lot with no problems, it just
>> works. I have never had the need to communicate enything more complex
>> than the exit code back to the parrent though.
>
> I've found it useful to pass an $ident which i can use in the
> run_on_finish callback to associate with the exit code.

Yes, but I consider this to be communication from the parrent on fork
time to the parrent on wait time. Even if the $ident is an reference
to something, the child can't change it for the parrent.

//Makholm 


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

Date: Wed, 16 Apr 2008 09:32:27 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Thread alternative for multi-processing?
Message-Id: <1eb01932-2967-4a0c-a1ba-ed565bad965b@e39g2000hsf.googlegroups.com>

On Apr 16, 11:10=A0am, Peter Makholm <pe...@makholm.net> wrote:
> nolo contendere <simon.c...@fmr.com> writes:
> >> I have used Parallel::ForkManager a lot with no problems, it just
> >> works. I have never had the need to communicate enything more complex
> >> than the exit code back to the parrent though.
>
> > I've found it useful to pass an $ident which i can use in the
> > run_on_finish callback to associate with the exit code.
>
> Yes, but I consider this to be communication from the parrent on fork
> time to the parrent on wait time. Even if the $ident is an reference
> to something, the child can't change it for the parrent.
>

True, perhaps I should have replied to the OP. I was simply sharing my
experience with Parallel::ForkManager, didn't mean to imply that the
$ident was a child->parent communication.


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

Date: 16 Apr 2008 16:48:56 GMT
From: xhoster@gmail.com
Subject: Re: Thread alternative for multi-processing?
Message-Id: <20080416124857.969$kM@newsreader.com>

howa <howachen@gmail.com> wrote:
> Sometimes, I want to take the advantage of multi-core processor, and
> make the full use of my CPU time,
>
> e.g. I have a function, which takes a file name as input, do some text
> processing (e.g. CPU intensive), and save it back.

The saving it back might be a problem.  Do the lines have to be saved
back in the same order they are originally present?  With parallel,
it requires special efforts to make that happen.

>
> I don't want to use thread, as it need to recompile perl on all my
> machines and I am not sure if it is stable enough to affect other
> apps.
>
> I don't mind to have a little overhead in using the fork mode (i.e.
> multi-process). I want to know are there  any recommended module for
> my purpose?
>
> For example, I am trying Parallel::ForkManager, POE::Wheel::Run, so
> anyone want to share the experiences?

In this case, I'd tend to role my own forking.  I generally use
Parallel::ForkManager for when the number of processes I want run is
greater than the number I want to run simultaneously, which doesn't seem to
be the case for you.  You certainly *can* use it in other cases, I just
don't see much need to.  I've looked into POE::Wheel::Run a few times but
never got over the activation barrier to actually use it.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Mon, 21 Apr 2008 00:48:17 -0700 (PDT)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: To find a quick way to list all files in the directory(and  subdirectory)
Message-Id: <fd72e77d-340e-482a-aedc-e2c2cd0ece53@x19g2000prg.googlegroups.com>

On Apr 21, 4:46 pm, "lofenee" <lofe...@gmail.com> wrote:
> Is there any function or module that can be used to list the content of a
> directory recursively? Like `ls -R`, but it doesn't work everywhere.

File::Find ?


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

Date: Mon, 21 Apr 2008 22:57:18 -0700 (PDT)
From: Ben Bullock <benkasminbullock@gmail.com>
Subject: Re: To find a quick way to list all files in the directory(and  subdirectory)
Message-Id: <f22d4d1a-d3fb-451d-b498-7b64de2eaaaa@w5g2000prd.googlegroups.com>

On Apr 21, 4:51 pm, "lofenee" <lofe...@gmail.com> wrote:

> Thank you~

You might also find the following article, which contains some
examples, useful:

http://www.usenix.org/publications/login/2007-04/pdfs/blank-edelman.pdf


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

Date: Thu, 17 Apr 2008 09:30:30 -0700 (PDT)
From: dave <davewu922@gmail.com>
Subject: Trouble  initializing multidimensional array
Message-Id: <d3241a3c-2ae2-437f-81d6-05ede1a50aa6@s50g2000hsb.googlegroups.com>

I have trouble  initializing  the following multidimensional array

my @Table = ( [],[],[],[] );

push (@Table [ 't1', 't2', 't3', 't4' ] ) ;
push (@Table [ 'x1', 'x2', 'x3', 'x4' ] );  # and so on

foreach my $next (@Table)
{
   if ( @$next[0] eq 'xx' )
   {
	# do something
   }
}

When I run the foreach loop, the first 4 times will have "Use of
uninitialized value"  error and then everything will be fine.
How can in initialize @Table so that the first entry should have 't1'
't2' .. .in it.

Thanks

David




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

Date: Thu, 17 Apr 2008 12:00:34 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Trouble  initializing multidimensional array
Message-Id: <48078232$0$87073$815e3792@news.qwest.net>

dave wrote:
> I have trouble  initializing  the following multidimensional array
> 
> my @Table = ( [],[],[],[] );
No need to do that.

my @Table;

If you had:

use strict;
use warnings;

You'd see errors with your syntax for push:

> 
> push (@Table [ 't1', 't2', 't3', 't4' ] ) ;
> push (@Table [ 'x1', 'x2', 'x3', 'x4' ] );  # and so on

perldoc -f push

"    push ARRAY,LIST "


> 
> foreach my $next (@Table)
> {
>    if ( @$next[0] eq 'xx' )

That's not how you access the data.

$next->[0]

perldoc perlreftut

>    {
> 	# do something
>    }
> }
> 
> When I run the foreach loop, the first 4 times will have "Use of
> uninitialized value"  error and then everything will be fine.
> How can in initialize @Table so that the first entry should have 't1'
> 't2' .. .in it.

Really?  Running your code I get:

Type of arg 1 to push must be array (not array slice) at - line 2, near 
"] ) "
Type of arg 1 to push must be array (not array slice) at - line 3, near 
"] )"


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

Date: Thu, 17 Apr 2008 13:51:16 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Trouble  initializing multidimensional array
Message-Id: <m1ej94nze3.fsf@dot-app.org>

dave <davewu922@gmail.com> writes:

> I have trouble  initializing  the following multidimensional array
>
> my @Table = ( [],[],[],[] );
>
> push (@Table [ 't1', 't2', 't3', 't4' ] ) ;
> push (@Table [ 'x1', 'x2', 'x3', 'x4' ] );  # and so on
>
> foreach my $next (@Table)
> {
>    if ( @$next[0] eq 'xx' )
>    {
> 	# do something
>    }
> }
>
> When I run the foreach loop, the first 4 times will have "Use of
> uninitialized value"  error and then everything will be fine.

What else would you expect? The first thing you added to @Table was refs
to four empty arrays.

    my @Table = ( [],[],[],[] );

Those array references aren't going away just because you push more onto
the end of @Table later on - they'll still be there.

> How can in initialize @Table so that the first entry should have 't1'
> 't2' .. .in it.

If you don't want four empty arrays to begin with, don't add them:

    my @Table;

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Thu, 17 Apr 2008 09:56:12 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Trouble initializing multidimensional array
Message-Id: <4262513e-8734-47e7-8349-956c88deb840@m73g2000hsh.googlegroups.com>

On Apr 17, 12:30=A0pm, dave <davewu...@gmail.com> wrote:
> I have trouble =A0initializing =A0the following multidimensional array
>
> my @Table =3D ( [],[],[],[] );
>
> push (@Table [ 't1', 't2', 't3', 't4' ] ) ;
> push (@Table [ 'x1', 'x2', 'x3', 'x4' ] ); =A0# and so on

you forgot the comma between the array and the value you want to push
onto the array.

push @Table, [ 't1', 't2', 't3', 't4' ];
push @Table, [ 'x1', 'x2', 'x3', 'x4' ];



>
> foreach my $next (@Table)
> {
> =A0 =A0if ( @$next[0] eq 'xx' )

$next is an array reference. i think you mean:
     if ( $next->[0] eq 'xx' )

> =A0 =A0{
> =A0 =A0 =A0 =A0 # do something
> =A0 =A0}
>
> }
>
> When I run the foreach loop, the first 4 times will have "Use of
> uninitialized value" =A0error and then everything will be fine.
> How can in initialize @Table so that the first entry should have 't1'
> 't2' .. .in it.
>


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

Date: Thu, 17 Apr 2008 10:27:11 -0700 (PDT)
From: dave <davewu922@gmail.com>
Subject: Re: Trouble initializing multidimensional array
Message-Id: <40bf6082-0891-4c44-9dc7-5d5e935cf93f@b1g2000hsg.googlegroups.com>

On Apr 17, 1:00 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:

Thanks ...

The push statement was a typo, it had a comma in the actual code.

I changed the code to something like the following and everything
seems to run.

my  @Table;

push (@Table, [ 't1', 't2', 't3', 't4' ] ) ;
push (@Table, [ 'x1', 'x2', 'x3', 'x4' ] );  # and so on

foreach my $next (@Table)
{
   if ( @$next->[0] eq 't1' )
   {
	my $col_1 = $next->[1];

   }
}


Thanks again.
David


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

Date: Thu, 17 Apr 2008 13:18:56 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Trouble initializing multidimensional array
Message-Id: <48079490$0$89391$815e3792@news.qwest.net>

dave wrote:
> On Apr 17, 1:00 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
> 
> Thanks ...
> 
> The push statement was a typo, it had a comma in the actual code.
> 
> I changed the code to something like the following and everything
> seems to run.
> 
> my  @Table;
> 
> push (@Table, [ 't1', 't2', 't3', 't4' ] ) ;
> push (@Table, [ 'x1', 'x2', 'x3', 'x4' ] );  # and so on
> 
> foreach my $next (@Table)
> {
>    if ( @$next->[0] eq 't1' )

Why do you keep wanting to put a '@' there?

Maybe this will explain:

  perldoc -q 'What is the difference between'

>    {
> 	my $col_1 = $next->[1];

See, no '@' is needed/wanted.

> 
>    }
> }


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

Date: Thu, 17 Apr 2008 11:32:41 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Trouble initializing multidimensional array
Message-Id: <anhkd5xtk6.ln2@goaway.wombat.san-francisco.ca.us>

On 2008-04-17, dave <davewu922@gmail.com> wrote:
>
> The push statement was a typo, it had a comma in the actual code.

Don't retype code; cut and paste, so that typos don't confuse the issue.

--keith



-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: Tue, 22 Apr 2008 16:01:41 -0400
From: Steve <SteveSpamTrap@yahoo.com>
Subject: Trying to fetch Basic Auth header in Mason
Message-Id: <676uh7F2nsmanU1@mid.individual.net>

	I have a very simple internal web application "protected" (more or 
less) by HTTP Basic Auth.  The app is written using Mason, and I'm 
trying to have it fetch the username of the current user from the HTTP 
headers.  At a high-level, one could do this by fetching the value of 
the header "Authorization", which looks like this:

Authorization: Basic sdfSDFssdfsdfSDF=

	... where the value consists of the word "Basic", followed by a space, 
followed by the username and password encoded with Base64.


	My little helper subroutine on my Mason page is straightforward enough:

sub getHeader {
	my $name = shift;
	my %headers = $r->headers_in;
	return $headers{$name};
}

	... as is calling it:

my $authorizationHeader = &getHeader( 'Authorization' );


	However, the value that I'm getting for "$authorizationHeader" in the 
example above is always the string "Basic".  Mason stops at the space, 
and won't return the Base64-encoded portion of the header value 
following that space.  I've played around with trying to return the 
value as an array rather than a scalar, but it hasn't made any difference.

	Is this an actual bug with Mason, or can anyone spot anything really 
stupid that I'm missing?  Thanks in advance!


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

Date: Thu, 17 Apr 2008 09:06:29 -0700 (PDT)
From: dave <davewu922@gmail.com>
Subject: uninitialized value in multidimensional array
Message-Id: <9426ddef-01bb-43bb-a62f-db50560fc5fb@f63g2000hsf.googlegroups.com>

I've the following perl :

my @Table = ([],[],[],[]);

push ( @Table, 'text1', 'test2', 'text3','text4');

foreach my $next (@Table))
{






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

Date: Thu, 17 Apr 2008 17:15:13 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: uninitialized value in multidimensional array
Message-Id: <48077791$0$26092$db0fefd9@news.zen.co.uk>

dave wrote:
> I've the following perl :
> 
> my @Table = ([],[],[],[]);
> 
> push ( @Table, 'text1', 'test2', 'text3','text4');
> 
> foreach my $next (@Table))
> {
> 

Nuke it from orbit.

-- 
RGB


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

Date: Thu, 17 Apr 2008 13:43:23 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: uninitialized value in multidimensional array
Message-Id: <m1iqygnzr8.fsf@dot-app.org>

dave <davewu922@gmail.com> writes:

> I've the following perl :
>
> my @Table = ([],[],[],[]);
>
> push ( @Table, 'text1', 'test2', 'text3','text4');
>
> foreach my $next (@Table))
> {

And your question is... ?

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Thu, 17 Apr 2008 12:35:05 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: uninitialized value in multidimensional array
Message-Id: <170420081235054975%jimsgibson@gmail.com>

In article
<9426ddef-01bb-43bb-a62f-db50560fc5fb@f63g2000hsf.googlegroups.com>,
dave <davewu922@gmail.com> wrote:

> I've the following perl :
> 
> my @Table = ([],[],[],[]);
> 
> push ( @Table, 'text1', 'test2', 'text3','text4');
> 
> foreach my $next (@Table))
> {

That is not a valid Perl program, so I can't tell what it is you are
trying to do, or under what circumstances you are getting the error
message in your subject line.

I suggest you use Data::Dumper to see what you have in @Table:

  use Data::Dumper;
  print Dumper(\@Table);

It might be illuminating.

Please read the guidelines for this group and try to adhere to them.
Thanks.

-- 
Jim Gibson

 Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
                http://www.usenet.com


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

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


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