[29606] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 850 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 14 11:09:47 2007

Date: Fri, 14 Sep 2007 08:09:09 -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           Fri, 14 Sep 2007     Volume: 11 Number: 850

Today's topics:
        click a <embed> object in WWW::Mechanize script? <jck11@msr.pchome.com.tw>
    Re: Commented braces <bik.mido@tiscalinet.it>
        csv, perl and German umlaute <abadiya@googlemail.com>
        How to implement IPC with scalars? <wolleric@gmx.de>
    Re: How to implement IPC with scalars? <ben@morrow.me.uk>
    Re: HTTP Filtering and Threads... <ben@morrow.me.uk>
        menu replacing <hugsandy@gmail.com>
        Oneliner problem with < and > in variable <antosim@gmail.com>
    Re: Oneliner problem with < and > in variable <peter@makholm.net>
    Re: Oneliner problem with < and > in variable <bik.mido@tiscalinet.it>
    Re: Oneliner problem with < and > in variable <antosim@gmail.com>
    Re: Oneliner problem with < and > in variable <bik.mido@tiscalinet.it>
    Re: Oneliner problem with < and > in variable <glennj@ncf.ca>
    Re: Oneliner problem with < and > in variable <glennj@ncf.ca>
    Re: Oneliner problem with < and > in variable <dummy@example.com>
    Re: parallel computing in perl? <bik.mido@tiscalinet.it>
    Re: parallel computing in perl? <jiehuang001@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 14 Sep 2007 17:15:33 +0800
From: "jck11" <jck11@msr.pchome.com.tw>
Subject: click a <embed> object in WWW::Mechanize script?
Message-Id: <fcdjl5$k7v$1@netnews.hinet.net>

hi all
Is there a method to click  a <embed> object by using WWW::Mechanize?
I am hungry for it :)




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

Date: Fri, 14 Sep 2007 11:31:20 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Commented braces
Message-Id: <i4lke39lt8v4ou03af15crv6cvnc49qj5f@4ax.com>

On Thu, 13 Sep 2007 23:52:09 -0700, "Wade Ward" <zaxfuuq@invalid.net>
wrote:

>Do you know how to reach Mr. Dondi through e-mail?

<ti tod nfni tod im tod mcl ta razalb>

Or else I'm on Jabber as <blazar@jabber.org>.


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, 14 Sep 2007 07:04:34 -0700
From:  abadiya <abadiya@googlemail.com>
Subject: csv, perl and German umlaute
Message-Id: <1189778674.598042.255890@50g2000hsm.googlegroups.com>

Hi,

I'm using Mason/Perl. At the moment I'm trying to pull data out of a
csv-file into an html file with the help of Perl. Works fine but I
have problems with the displayal of German umlaute. Sometimes they are
displayed, sometimes I get questionmarks where the umlaute should be.
Changes almost every time I refresh the page.

I've got this line at the beginning of my code to force the page to
use utf8 but it won't work.
<%method .utf8></%method>

Can you help me?

Best Wishes



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

Date: Fri, 14 Sep 2007 09:54:44 -0000
From:  Eric <wolleric@gmx.de>
Subject: How to implement IPC with scalars?
Message-Id: <1189763684.300371.276180@19g2000hsx.googlegroups.com>

Hey newsgroup,

first of all, sorry for double-posting but I guess the subject of my
last post was perhaps not hitting the spot or so... It can be found
here: http://groups.google.de/group/comp.lang.perl.misc/browse_thread/thread/4fc35c6fa1a8f488/37ab354f1af7b6e7?hl=de#37ab354f1af7b6e7

The main problem is that while pump()ing a child's output into my $out
scalar, new output is not fed sequentially, so I always get back the
entire output the program gave since it started.
Any ideas? Please, I really need this stuff. I can't find any examples
on the net apart from those in perlicp, which aren't explained in
great detail..

Thanks,
Eric



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

Date: Fri, 14 Sep 2007 14:28:19 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How to implement IPC with scalars?
Message-Id: <jseqr4-jg1.ln1@osiris.mauzo.dyndns.org>


Quoth Eric <wolleric@gmx.de>:
> Hey newsgroup,
> 
> first of all, sorry for double-posting but I guess the subject of my
> last post was perhaps not hitting the spot or so... It can be found
> here:
<deleted long URL>

Please don't do this: either continue the thread, or start a new thread
explaining from the beginning what you are talking about.

> The main problem is that while pump()ing a child's output into my $out
> scalar, new output is not fed sequentially, so I always get back the
> entire output the program gave since it started.

Read the docs for IPC::Run, in particular the example in the section
"Using regexps to match output".

Ben



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

Date: Fri, 14 Sep 2007 14:19:46 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: HTTP Filtering and Threads...
Message-Id: <iceqr4-jg1.ln1@osiris.mauzo.dyndns.org>


Quoth Dan <danett18@yahoo.com.br>:
> 1) I have a code in perl which is doing a HTTP request and getting a
> response and saving in a variable, so I want to filter a specific
> value of a field. My code is more or less like this one:
> 
> next unless /^<input name/i;

You are trying to parse HTML with regular expressions. This is a very
bad idea. I would strongly recommend using HTML::Parser, or another
module capable of actually parsing HTML.

> my ($name, $value) = $_ =~ /input name="(.*)Name" type=.*
> value="(.*)">/i;

This will fail because the * regex operator is 'greedy': it always takes
as much text as it can. This is why you are always getting the last
value in your example below: the first .* matches everything from the
first 'name="' all the way to the middle of the last <input> tag.

> if ((length($value)) > 1){
>      $MiddleName = $value;
>      #Some Stuff Code...
>      print "$MiddleName";<br><br>
                           ^^^^^^^^
This is not Perl. Please post the *actual* code you ran. It make things
simpler :).

> }
> 
> However the HTTP request return a HTML code that is more or less like
> this:
> 
> #Some non relevante HTML stuff...
> <input name="$mdName" type="hidden" value="Silva">
> #Some non relevante HTML stuff...
> <input name="Name" type="hidden" value="Silva">
> <input name="mdName" type="hidden" value="Daniel">
> #Some non relevante HTML stuff...<code>
> 
> The problem is that my code is getting the value of "mdName" which is
> "Daniel" and I want it get the value of "$mdName" which is "Silva" and
> if it is missing (blank) I want to get the value of "Name" which in
> the example also is "Silva". But I never want to get the value of
> "mdName" which is "Daniel" and is what always is happening. :(
> 
> Obs.: I also tried (without sucess) use:
> 
> * my ($name, $value) = $_ =~ input name="\"\$mdName\" type=.*
> value="(.*)">/i;
> 
> * my ($name, $value) = $_ =~ m/input name=\"\$mdName\" type=.*
> value="(.*)">/i;
> 
> * my ($name, $value) = $_ =~ input name="\/$mdName\/" type=.*
> value="(.*)">/i;
> 
> * my ($name, $value) = $_ =~ m/input name="\/$mdName\/" type=.*
> value="(.*)">/i;

Uh, why? Don't just randomly try things hoping one will work; instead,
understand what is going wrong and fix it.

> 2) In the some program I have a piece of code which list all users and
> do a loop for call the function which will get detailed information of
> each user (the code in question 1 is part of this function). The
> snippet is like this one:
> 
> # Some irrelevant code stuff...
> 
> (my $ruid, @userIDs) = &GetUserList($start, $end);

Don't call subs with &. It was a Perl 4 practice, and has some strange
side-effects in Perl 5.

>    if ($userIDs[0] == -1) { exit(0); }
> 
>    foreach $userID (@userIDs) {
>       &GetUserData($name, $middlename, $lname, $bdate);

Your sub GetUserData seems to be directly updating the variables pased
to it. This is a bad idea as it is not what someone reading the code
will expect. It would be better to return a list and call like

    my ($name, $middlename, $lname, $bdate) = GetUserData;

Also, it seems to be getting the value of the user ID from a global
variable: again, it would be better to pass it to the function.

> 
>       print "$userID\t: $name, $middlename, $lname, $bdate";
> 
>       # Some irrelevant code stuff...
> 
>    }
> 
> # Some irrelevant code stuff...
> 
> The function GetUserData() is really slow, it do HTTP Request, parse
> some HTML stuff and the amount of users is big. So I would like to add
> thread support to it, in a fashion that I could have for example 8
> instances of this code running in paralel. :)

Note that this may well not make it run faster. Unless you have 8
processors (lucky you ;) ), it will just make things slower.

One thing that may be slowing things down is if you are fetching and
parsing the same page many times. You may want to look at the Memoize
module as an easy way of avoiding that.

> I had looked at http://perldoc.perl.org/threads.html, but it doesn't
> helped so much. I belive I should add the thread support in a fashion
> that it work directly with the foreach loop instruction and
> GetUserData(), right?

The simplest way to multi-thread the above is something like

use threads;

foreach $userID (@userIDs) {
    async {
        my ($name, $middlename, $lname, $bdate) =
            GetUserData($userID);

        print "$userID\t: $name, $middlename, $lname, $bdate";

        # Some irrelevant code stuff...
    }
}

This will run each request in a new thread; but as you have identified,
the output will come out any which way. If you really want to use
threads, you want to use something like Thread::Queue to pass the
results back to the parent thread, which can then deal with printing
them.

> However I want to take care to doesn't overwrite data (in C when we
> deal with threads we have some unsafe functions that can overwrite
> values - which is not good)...

This is not an issue in Perl. Threads have completely separate
variables: threads in Perl are more like Unix' fork than like
traditional C threading.

> 3) The Perl2exe (http://www.indigostar.com/perl2exe.htm) is the best
> option to convert Perl code to Executables? It really work well? Even
> with complicated and sophisticated code (using thread, raw sockets,
> windows registry access, etc)?

I've never used perl2exe (I understand it's not free?), but I have had
success with PAR, which you can install from CPAN.

> Well, that's my first code in perl, so sorry for ugly/bad code (and
> also I'm not a programmer, just a curious:). hehe

That's fine: there's nothing wrong with writing bad code when you are
first learning :). The code you posted isn't half as bad as some we see
in this group, anyway...

> Thank you and sorry for amount (of dumb and off-topic) questions.

Not off-topic at all, and not dumb neither.

Ben



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

Date: Fri, 14 Sep 2007 13:35:47 -0000
From:  jimmy <hugsandy@gmail.com>
Subject: menu replacing
Message-Id: <1189776947.959834.141230@g4g2000hsf.googlegroups.com>

Hi all
now this may seem trivial to many here and probably the solution is
embedded in some question asked before  but i have zero know how of
perl (have used grep as a command and little searching and extracting)
but i have been working on this website and use some gui based tool
but i guess it will be really faster and efficient doing this using
perl but have no idea.. perl in scripting
this is what i intend to do there is a menu on about 25 lines inside
the tags

<div id="menu"><!--This is the navigation menu-->
	-
	-
	-
	-
	-
	-
	-
	-

<!-- End Navigation--></div>

only the starting and endline lines (shown here) are constant thru all
the files in all the directories
now i believe these can be used as regular expressing and i can do a
search replace in all the files on all the lines inside these tags
with new lines i have
i saw many posts with features resembling this but dont know if i can
use them for this can
some point to a solution

Thanks

Ps: have already started learning perl.. hope to make it to beginner
level soon



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

Date: Fri, 14 Sep 2007 01:41:19 -0700
From:  Ansim <antosim@gmail.com>
Subject: Oneliner problem with < and > in variable
Message-Id: <1189759279.573363.171330@r34g2000hsd.googlegroups.com>

Hello,

I have this oneliner
$_PERL -ni -we 'BEGIN{@content=3D'$_new_start'} if(/'$_start'/){s//
@content/;print}else{print}' SMOinfo.xml

where $_start is <Action name=3D"abc" id=3D"_XX_"> , a xml pragma, and
$_new_start is <!-- <Action.....>, same xml pragma but with comment
marks first.

When this oneliner is executet i receives this error:
"Unterminated <> operator at -e line 1.

I've tried several settings in the @content=3D'$_new_start' statement,
everyone failing with different error codes.
Tried to change the ' to ` or " or "' or =B4 and without.


The idea is to, in a script,  auto magically comment out Action
settings in the xml file, if they are commented in another file.

The one liner is executet once more and end the comment with

$_PERL -ni -we 'BEGIN{@content=3D'$_new_end'} if(/'$_end'/){s//
@content/;print}else{print}' SMOinfo.xml
where  $_end=3D"</Action name=3D"abc" id=3D"_XX_">", $_new_end=3D"</Action
id=3D"_XX_"> -->"

Any suggestions on how to solve this?

BR
//Anders



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

Date: Fri, 14 Sep 2007 08:54:44 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <87odg5pqy3.fsf@hacking.dk>

Ansim <antosim@gmail.com> writes:

> I have this oneliner
> $_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
> @content/;print}else{print}' SMOinfo.xml
>
> where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
> $_new_start is <!-- <Action.....>, same xml pragma but with comment
> marks first.

Could you try to cut'n'paste exactly what you're writing in you
oneliner. In the above $_new_start isn't anything but undef. 

//Makholm


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

Date: Fri, 14 Sep 2007 11:38:51 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <8klke31ch0cckarimb7nesv6jj9tqh70n3@4ax.com>

On Fri, 14 Sep 2007 01:41:19 -0700, Ansim <antosim@gmail.com> wrote:

>I have this oneliner
>$_PERL -ni -we 'BEGIN{@content=3D'$_new_start'} if(/'$_start'/){s//
>@content/;print}else{print}' SMOinfo.xml

Quote the inner single quotes. BTW: a shell problem, not a Perl one...


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, 14 Sep 2007 05:20:56 -0700
From:  Ansim <antosim@gmail.com>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <1189772456.823051.259550@o80g2000hse.googlegroups.com>

If i set @content='"$_new_start"' and if(/<Activity.*_MM_FRP_FILE"\>/)

_new_start="<!-- <Activity Name="Firmware Upgrade"
Build_id="_MM_FRP_FILE">" by some grep, nawk.

(Of course not the first and last ".)

i get following output:

Unterminated <> operator at -e line 1.

and nothing is done in the SMOinfo.xml

But, if i set @content='"$_start"' where _start="<Activity
Name="Firmware Upgrade" Build_id="_MM_FRP_FILE">"
then the line in SMOinfo.xml is changed to
Activity Name="Firmware Upgrade" Build_id="_MM_FRP_FILE"  ,  note! the
< > is removed. Not what i wanted.

The oneliner is executed inside a ksh script.

//Anders



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

Date: Fri, 14 Sep 2007 16:16:19 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <5o5le3d09d8oh80fsukj9vkuqn8u4e87md@4ax.com>

On Fri, 14 Sep 2007 05:20:56 -0700, Ansim <antosim@gmail.com> wrote:

>If i set @content='"$_new_start"' and if(/<Activity.*_MM_FRP_FILE"\>/)
>
>_new_start="<!-- <Activity Name="Firmware Upgrade"
>Build_id="_MM_FRP_FILE">" by some grep, nawk.
>
>(Of course not the first and last ".)
>
>i get following output:
>
>Unterminated <> operator at -e line 1.
>
>and nothing is done in the SMOinfo.xml
>
>But, if i set @content='"$_start"' where _start="<Activity
>Name="Firmware Upgrade" Build_id="_MM_FRP_FILE">"
>then the line in SMOinfo.xml is changed to
>Activity Name="Firmware Upgrade" Build_id="_MM_FRP_FILE"  ,  note! the
>< > is removed. Not what i wanted.
>
>The oneliner is executed inside a ksh script.

I think all shells behave more or less the same wrt basic quoting. Can
you post the complete oneliners in their variations and explain how
they fail to work please?

From the first post I gathered that you had a quoting problem of
single quotes inside single quotes. You overcome it like so:

  'something \'strange\' indeed'

Here you brought up double quotes. I could not follow your words in
detail admittedly *also* because I'm in a hurry. But remember that
double quotes *interpolate* in Perl, and this may matter.


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: 14 Sep 2007 14:54:34 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <slrnfel85b.db8.glennj@smeagol.ncf.ca>

At 2007-09-14 04:41AM, "Ansim" wrote:
>  Hello,
>  
>  I have this oneliner
>  $_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
>  @content/;print}else{print}' SMOinfo.xml
>  
>  where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
>  $_new_start is <!-- <Action.....>, same xml pragma but with comment
>  marks first.
>  
>  When this oneliner is executet i receives this error:
>  "Unterminated <> operator at -e line 1.

You're trying to set an array to a single value, but you don't quote
that value in any way.  You don't even quote your shell variable.

    $ bash
    $ _start='<Action name="abc" id="_XX_">'
    $ _new_start='<!-- '"$_start"

    $ perl -lwe 'BEGIN {@content='$_new_start'} END {print "@content\n"}'
    Unterminated <> operator at -e line 1.

Try this:

    $ perl -lwe 'BEGIN {@content=q('"$_new_start"')} END {print "@content"}'
    <!-- <Action name="abc" id="_XX_">

Similarly, add double quotes around your shell variable "$_start"

Also, you print() in both cases of your if(), so why not use -p instead
of -n?

You only use @content as a scalar anyway.  You're apparently just adding
"$_new_start" to the beginning of any line that contains "$_start", so
you can just do:

    $_PERL -pi -we '/\Q'"$_start"'/ and print qq('"$_new_start"')' SMOinfo.xml

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


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

Date: 14 Sep 2007 14:57:12 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <slrnfel8a9.db8.glennj@smeagol.ncf.ca>

At 2007-09-14 10:54AM, "Glenn Jackman" wrote:
> $_PERL -pi -we '/\Q'"$_start"'/ and print qq('"$_new_start"')' SMOinfo.xml

Should probably be q() not qq()

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


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

Date: Fri, 14 Sep 2007 15:01:35 GMT
From: "John W. Krahn" <dummy@example.com>
Subject: Re: Oneliner problem with < and > in variable
Message-Id: <jnxGi.64220$vP5.8784@edtnps90>

Ansim wrote:
> 
> I have this oneliner
> $_PERL -ni -we 'BEGIN{@content='$_new_start'} if(/'$_start'/){s//
> @content/;print}else{print}' SMOinfo.xml
> 
> where $_start is <Action name="abc" id="_XX_"> , a xml pragma, and
> $_new_start is <!-- <Action.....>, same xml pragma but with comment
> marks first.
> 
> When this oneliner is executet i receives this error:
> "Unterminated <> operator at -e line 1.
> 
> I've tried several settings in the @content='$_new_start' statement,
> everyone failing with different error codes.
> Tried to change the ' to ` or " or "' or ´ and without.
> 
> 
> The idea is to, in a script,  auto magically comment out Action
> settings in the xml file, if they are commented in another file.
> 
> The one liner is executet once more and end the comment with
> 
> $_PERL -ni -we 'BEGIN{@content='$_new_end'} if(/'$_end'/){s//
> @content/;print}else{print}' SMOinfo.xml
> where  $_end="</Action name="abc" id="_XX_">", $_new_end="</Action
> id="_XX_"> -->"
> 
> Any suggestions on how to solve this?

In perl one-liners:

-n ' if ( // ) { s///; print } else { print } '

Is usually written as:

-p ' s/// '

So:

$_PERL -ni -we 'BEGIN{@content='$_new_start'} 
if(/'$_start'/){s//@content/;print}else{print}' SMOinfo.xml

*Should* be written as:

$_PERL -pi -we 'BEGIN{$content='$_new_start'} s/'$_start'/$content/' SMOinfo.xml

Or perhaps just:

$_PERL -pi -we 's/'$_start'/'$_new_start'/' SMOinfo.xml


If that doesn't work then you could try something like this:

$_PERL -spi -we 's/$x/$y/o' -- -x="$_start" -y="$_new_start" SMOinfo.xml




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: Fri, 14 Sep 2007 11:26:37 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: parallel computing in perl?
Message-Id: <dskke3tuoctv59sdbrqclk8vm2b4lqa7kn@4ax.com>

On Thu, 13 Sep 2007 13:39:51 -0700, Jie <jiehuang001@gmail.com> wrote:

>next loop will overwrite it with a new generated file. There is no
>problem because the overwriting happens after each process is
>finished. now when I open 10 parallel processing for example, will
>those 10 temporary files or 10 temporary hashs/arrays/variables get
>messed up????

Variables belong each to their own process. As far as the files are
concerned, just create ten *different* ones. File::Temp may be useful.


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, 14 Sep 2007 07:27:12 -0700
From:  Jie <jiehuang001@gmail.com>
Subject: Re: parallel computing in perl?
Message-Id: <1189780032.080587.32790@50g2000hsm.googlegroups.com>


Hi, thank you very much for the replies.

I think below would be the code to do it.
I don't know if I used the right syntax to open a temporary file...
Also, I don't know if i need to use "$pm->wait_all_children;" as
suggested by Peter

==========================================================
use File::Temp
use Parallel::ForkManager;

my $pm = new Parallel::ForkManager(10);

for $data (1 .. 1000) {
    my $pid = $pm->start and next;
    open TEMP_FILE, tempfile();
    ## Do something with this temp_file
    $pm->finish;
}
=========================================================






On Sep 14, 5:26 am, Michele Dondi <bik.m...@tiscalinet.it> wrote:
> On Thu, 13 Sep 2007 13:39:51 -0700, Jie <jiehuang...@gmail.com> wrote:
> >next loop will overwrite it with a new generated file. There is no
> >problem because the overwriting happens after each process is
> >finished. now when I open 10 parallel processing for example, will
> >those 10 temporary files or 10 temporary hashs/arrays/variables get
> >messed up????
>
> Variables belong each to their own process. As far as the files are
> concerned, just create ten *different* ones. File::Temp may be useful.
>
> 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: 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 850
**************************************


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