[30626] in Perl-Users-Digest
Perl-Users Digest, Issue: 1871 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 23 18:11:03 2008
Date: Tue, 23 Sep 2008 15:09:38 -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, 23 Sep 2008 Volume: 11 Number: 1871
Today's topics:
Re: expect.pm - stdout buffering issue <glennj@ncf.ca>
Re: expect.pm - stdout buffering issue <yandry77@gmail.com>
Re: expect.pm - stdout buffering issue <josef.moellers@fujitsu-siemens.com>
Re: expect.pm - stdout buffering issue <5502109103600001@t-online.de>
Re: FAQ 1.14 What is a JAPH? (Randal L. Schwartz)
Re: How to unable the use of tainted mode in a CGI scri <spamtrap@dot-app.org>
Re: How to unable the use of tainted mode in a CGI scri <azol@non-non-non>
Re: How to unable the use of tainted mode in a CGI scri <azol@non-non-non>
Re: How to unable the use of tainted mode in a CGI scri <azol@non-non-non>
Re: How to unable the use of tainted mode in a CGI scri <spamtrap@dot-app.org>
Re: HTTP::Request response <john@castleamber.com>
Re: IPC:Shareable <tzz@lifelogs.com>
Re: IPC:Shareable <tzz@lifelogs.com>
Re: IPC:Shareable <tzz@lifelogs.com>
Re: IPC:Shareable <clauskick@hotmail.com>
Re: IPC:Shareable <clauskick@hotmail.com>
Re: IPC:Shareable <clauskick@hotmail.com>
Re: Regular express for <p>, <ul> and <ol> tags <news@lawshouse.org>
Re: Regular express for <p>, <ul> and <ol> tags <news@lawshouse.org>
Re: Replacing binary data containing & using perl in HP <spamtrap@dot-app.org>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 23 Sep 2008 13:48:18 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <slrngdhst3.kpj.glennj@smeagol.ncf.ca>
At 2008-09-23 06:35AM, "Andry" wrote:
> Hi all,
> I have the following script:
> ******************************************************************
> #!/usr/bin/perl -w
> use Expect;
>
> $timeout = 5;
> $|=1;
>
> $exp = new Expect();
> $exp->raw_pty(1);
>
> $exp->log_file("output.log", "w");
>
> $exp->spawn("ssh -l username 10.17.39.29");
> $exp->expect($timeout, [ "[Pp]assword" => sub { $_[0]->send("password
> \n"); } ]);
> $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls -l
> \n"); } ]);
> sleep 2;
> $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls
> \n"); } ]);
> sleep 5;
In my experience (with expect rather than expect.pm), if you need to
sleep, your match patterns are wrong. In particular, if you're trying
to match your shell prompt, you should anchor your regex.
--
Glenn Jackman
Write a wise saying and your name will live forever. -- Anonymous
------------------------------
Date: Tue, 23 Sep 2008 07:31:23 -0700 (PDT)
From: Andry <yandry77@gmail.com>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <5d29b83a-a89f-48fc-8963-0602e2b19c91@k13g2000hse.googlegroups.com>
On 23 Set, 15:48, Glenn Jackman <gle...@ncf.ca> wrote:
> At 2008-09-23 06:35AM, "Andry" wrote:
>
>
>
> > =A0Hi all,
> > =A0I have the following script:
> > =A0******************************************************************
> > =A0#!/usr/bin/perl -w
> > =A0use Expect;
>
> > =A0$timeout =3D 5;
> > =A0$|=3D1;
>
> > =A0$exp =3D new Expect();
> > =A0$exp->raw_pty(1);
>
> > =A0$exp->log_file("output.log", "w");
>
> > =A0$exp->spawn("ssh -l username 10.17.39.29");
> > =A0$exp->expect($timeout, [ "[Pp]assword" =3D> sub { $_[0]->send("passw=
ord
> > =A0\n"); } ]);
> > =A0$exp->expect($timeout, [ "prompt-string" =3D> sub { $_[0]->send("ls =
-l
> > =A0\n"); } ]);
> > =A0sleep 2;
> > =A0$exp->expect($timeout, [ "prompt-string" =3D> sub { $_[0]->send("ls
> > =A0\n"); } ]);
> > =A0sleep 5;
>
> In my experience (with expect rather than expect.pm), if you need to
> sleep, your match patterns are wrong. =A0In particular, if you're trying
> to match your shell prompt, you should anchor your regex.
>
> --
> Glenn Jackman
> =A0 =A0 Write a wise saying and your name will live forever. -- Anonymous
I'm not sure to understand what you mean, but the problem is not in my
match pattern ("prompt-string" was just a med up example...).
The expect function matches what I need (as you can see in the debug
generated by exp_internal) but I have a "timing" issue with execution
of sleep commands and also the output of send commands is not sent to
STDOUT when expected (see previous posts).
It looks like expect objects do not send their output to STDOUT
correctly (buffering issue?).
Andrea
------------------------------
Date: Tue, 23 Sep 2008 17:11:15 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <gbb0ug$6eq$1@nntp.fujitsu-siemens.com>
Andry wrote:
> output anyway).
> The commands should be executed in the following order:
> ls -l
> sleep 2
> ls
> sleep 5
>
> Instead they are executed like that:
> sleep 2
> ls -l
> sleep 5
> ls (only visible if soft_close is present and not captured by log_file
> anyway)
>
> Any idea?
It could very well be a buffering issue.
You could check by adding a "print STDERR "Got password prompt, sending
password\n" to the anonymous sub that's executed when "[Pp]assword" is
matched, and liekwise for the other subs.
Josef
BTW You *do* know, that you had the password in your output?
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Tue, 23 Sep 2008 18:01:06 +0200
From: Josef Moellers <5502109103600001@t-online.de>
Subject: Re: expect.pm - stdout buffering issue
Message-Id: <gbb493$i2m$02$1@news.t-online.com>
Andry wrote:
> Hi all,
> I have the following script:
> ******************************************************************
> #!/usr/bin/perl -w
> use Expect;
>
> $timeout = 5;
> $|=1;
>
> $exp = new Expect();
> $exp->raw_pty(1);
>
> $exp->log_file("output.log", "w");
>
> $exp->spawn("ssh -l username 10.17.39.29");
> $exp->expect($timeout, [ "[Pp]assword" => sub { $_[0]->send("password
> \n"); } ]);
> $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls -l
> \n"); } ]);
> sleep 2;
> $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("ls
> \n"); } ]);
> sleep 5;
>
> $exp->log_file(undef);
>
> $exp->expect($timeout, [ "prompt-string" => sub { $_[0]->send("exit
> \n"); } ]);
> ******************************************************************
>
> When I run the script, the console (stdout) shows:
> 1) ssh (login...)...
> 2) sleeping 2 seconds
> 3) "ls -l" output
> 4) sleeping 5 seconds
> ... the script quits without displaying the output of the second
> command "ls"
> Even the log file does not contain the missing output.
On my way home, I have been thinking about this (with this miserable
weather one *has* to think about something else) ...
In a wider sense, it has nothing to do with buffering.
What happens is:
You (disguised as a Perl/Expect script) wait for the password prompt and
send the password. Then you wait for the shell prompt and send the ls
command. Then you sleep for 2 seconds. In the meantime, the remote "ls
-l" produces output, but there is no-one there to notice.
Then you wait for the next shell prompt. *Now* you have to sift through
ls' output to look for the prompt (btw. here Glenn's remark about
anchoring comes into play, if one of the file names would contain the
prompt as a substring!). While sifting though the output, it will be
echoed to the console.
When you find the prompt, you send the next "ls" command and the
previous section hits you again.
So, it's not classical buffering but rather a postponed reading/echoing
of output produced earlier (of course, pedantics would call this
buffering, too, ...)
What you are expecting is the equivalent of
expect(prompt)
send("ls -l\r")
expect(prompt) << Here you get "ls -l"'s output
sleep 2
send("ls\r")
expect(prompt) << Here you get "ls"'s output
sleep 5;
HTH,
Josef
--
Mails please to josef dot moellers
and I'm on gmx dot de.
------------------------------
Date: Tue, 23 Sep 2008 08:57:39 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: PerlFAQ Server <brian@stonehenge.com>
Subject: Re: FAQ 1.14 What is a JAPH?
Message-Id: <86ej3a4zyk.fsf@blue.stonehenge.com>
>>>>> "PerlFAQ" == PerlFAQ Server <brian@stonehenge.com> writes:
PerlFAQ> print "Just another Perl hacker, ";
PerlFAQ> Note the trailing comma and space, which allows the addition of
PerlFAQ> other JAxH clauses for his many other interests.
Actually, it was just a comma, not a comma and space. This made it nicely
25 chars, which nicely formed a 5x5 grid which I used in at least a few
of the JAPHs.
print "Just another Perl hacker,"; # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Tue, 23 Sep 2008 12:38:09 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <m1y71izuku.fsf@dot-app.org>
Peter Scott <Peter@PSDT.com> writes:
> I'm curious; what happens if you run a trivial CGI program with -T on this
> host? Because I can't figure out how they would prohibit -T without
> building perl from a customized source
They could be running them in mod_perl's CGI emulation. Taint mode
must be specified when the interpreter is started. So if you have a
script that's running in Apache::Registry that has a -T in the #!
line, and the sysadmin hasn't enabled Taint mode globally with the
"PerlTaintCheck On" directive in httpd.conf, then you'll get a warning
to the effect that it's too late to use -T.
Come to think of it, you might get that warning whether Taint mode is
enabled globally or not - I've never tried using -T when it's already
been enabled with PerlTaintCheck.
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 23 Sep 2008 23:11:50 +0200
From: Azol <azol@non-non-non>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <MPG.23437a054cc03db49897ec@news.free.fr>
In article <CJZBk.113$Cl1.5@newsfe01.iad>, tim@burlyhost.com says...
> Azol wrote:
>
> > Hello.
> >
> > I have to use a long perl script which use the "tainted mode" (-T
> > option), but the hoster we use doesn't allow this option unless on
> > dedicated server (and, of course, we can't pay a dedicated server).
> >
> > What I have to do to remove the tainted mode in the script ?
> >
> > I'm using PERL sometimes, but don't know very well what implies this
> > "tainted mode" option. However, I suppose removing the "-T" on bash
> > line isn't enough :(
> >
> > Could you tell me, please.
>
> What do you mean that your host won't allow you to use Taint mode? Do
> you mean they don't allow Perl, or actually don't allow you to use
> Taint mode? That seems crazy, are you sure that's the case and there
> wasn't some misunderstanding about the question or feature? I can't
> imagine anyone in their right mind denying a user from using a switch
> that helps keep your site (and by proxy, their service your site runs
> on) from being exposed to problems with a potentially insecure portion
> of your code? Is your script perhaps set to run in the background,
> launching a child process or something? This is a really strange thing
> to hear.
>
Thanks to all of you : it's very cool to get all of your returns :)
Yes, it's the reply of their support : remove the -T option : oops :(
Their site is http://www.1and1.fr/
Also, effectively, the script manage a child process : what do you think
about that ?
------------------------------
Date: Tue, 23 Sep 2008 23:25:46 +0200
From: Azol <azol@non-non-non>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <MPG.23437d4564ba39269897ed@news.free.fr>
In article <pan.2008.09.23.09.46.43.17580@PSDT.com>, Peter@PSDT.com
says...
> On Mon, 22 Sep 2008 19:17:48 +0200, Azol wrote:
> > I have to use a long perl script which use the "tainted mode" (-T
> > option), but the hoster we use doesn't allow this option unless on
> > dedicated server (and, of course, we can't pay a dedicated server).
>
> I'm curious; what happens if you run a trivial CGI program with -T on this
> host? Because I can't figure out how they would prohibit -T without
> building perl from a customized source, and I cannot fathom a
> justification for doing so.
>
>
Well, I've tried with this trivial CGI :
#!/usr/bin/perl -T
use strict;
use warnings;
print "Content-type: text/html\n\n<HTML><BODY><P>Hello World !</P>
</BODY></HTML>";
exit 0;
It returns a "Error 500 - Internal server error" with -T
It works without -T
So, its seems 1and1.fr really doesn't allow the tainted mode.
------------------------------
Date: Tue, 23 Sep 2008 23:30:40 +0200
From: Azol <azol@non-non-non>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <MPG.23437e69bd4f2c069897ee@news.free.fr>
In article <CJZBk.113$Cl1.5@newsfe01.iad>, tim@burlyhost.com says...
> What do you mean that your host won't allow you to use Taint mode? Do
> you mean they don't allow Perl, or actually don't allow you to use
> Taint mode?
>
They allow Perl, but not the -T option (so, tainted mode)
------------------------------
Date: Tue, 23 Sep 2008 17:40:40 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: How to unable the use of tainted mode in a CGI script ?
Message-Id: <m1r67ao813.fsf@dot-app.org>
Azol <azol@non-non-non> writes:
> Well, I've tried with this trivial CGI :
>
> #!/usr/bin/perl -T
> use strict;
> use warnings;
> print "Content-type: text/html\n\n<HTML><BODY><P>Hello World !</P>
> </BODY></HTML>";
> exit 0;
You don't need exit() here; it's only needed when you want to
interrupt the normal flow of execution.
> It returns a "Error 500 - Internal server error" with -T
That's just a generic error that essentially means "something went
wrong." The actual error message that was printed by Perl is in the
web server's error log.
> It works without -T
>
> So, its seems 1and1.fr really doesn't allow the tainted mode.
Maybe. What's in the error log?
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 23 Sep 2008 20:24:55 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: HTTP::Request response
Message-Id: <Xns9B229CD07DDBDcastleamber@130.133.1.4>
Sharif <mislam@nospam.ciuc.edu> wrote:
> I need extract the resulting link from the response. I am using
> HTTP::Request.
>
> How do I extract the 'uri' string from the has
> (http://www.sciencedirect.com/science//journal/09567151)?
>
>
> use strict;
> use Data::Dumper;
> use HTTP::Request;
> use LWP::UserAgent;
>
>
> my $url =
> "http://openurl.library.uiuc.edu/sfxtst3?url_ver=Z39.88-2004&url_ctx_fm
> t=infofi/fmt:kev:mtx:ctx&ctx_enc=info:ofi/enc:UTF-8&ctx_ver=Z39.88-2004
> &rfr_id=info:sid/sfxit.com:azlist&sfx.ignore_date
>
>
> my $req = new HTTP::Request ('GET' , $url);
>
>
> my $ua = LWP::UserAgent->new;
> my $response = $ua->request($req);
> print Dumper ($response->request);
RTFM?
$r->uri( $val )
This is used to get/set the uri attribute.
--
John http://johnbokma.com/ - Hacking & Hiking in Mexico
Perl help in exchange for a gift:
http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
------------------------------
Date: Tue, 23 Sep 2008 08:23:46 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: IPC:Shareable
Message-Id: <86d4ivf125.fsf@lifelogs.com>
On Tue, 23 Sep 2008 02:56:58 -0700 (PDT) Snorik <clauskick@hotmail.com> wrote:
S> Ok, when testing with another directory tree, I saw the following:
S> IPC::Sha(in cleanup) IPC::ShareLite store() error: No space left on
S> device at /opt/iw-home/iw-perl/site/lib/Tie/ShareLite.pm line 366
S> Then, on retry, it worked again - therefore my question: Do I have to
S> clean up anything after I used it?
S> I tried using "destroy => 'yes'", but that yields "IPC::ShareLite
S> fetch() error: Invalid argument at /opt/iw-home/iw-perl/site/lib/Tie/
S> ShareLite.pm line 342", telling me (not sure) that the object is
S> destroyed too early.
S> Some explanation what to do for this would be great :)
You need to increase your shared memory. This is different for every
OS. For Solaris, see
e.g. http://publib.boulder.ibm.com/tividd/td/ITAME/SC32-1351-00/en_US/HTML/am51_perftune34.htm
Give it at least 10 times the default, unless your system is short on memory.
Ted
------------------------------
Date: Tue, 23 Sep 2008 08:27:31 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: IPC:Shareable
Message-Id: <868wtjf0vw.fsf@lifelogs.com>
On Mon, 22 Sep 2008 07:57:41 -0700 (PDT) Snorik <clauskick@hotmail.com> wrote:
S> if ($pid)
S> {
S> push(@children, $pid);
S> }
S> elsif ($pid == 0)
S> {
S> use File::Find::Rule;
S> my @fbas = File::Find::Rule->file->in("/default/main/www/$rg/$gg/
S> WORKAREA/workarea/$gg_fba");
S> $ipc->lock(LOCK_EX);
S> $shared{$gg} = \@fbas;
S> $ipc->unlock();
S> exit (0);
S> }
S> else
S> {
S> print STDERR "\nERROR: fork failed: $!\n";
S> }
S> }
S> foreach (@children)
S> {
S> waitpid($_, 0);
S> }
S> return %shared;
S> And in the calling script:
S> my %fba_ref = Package::get_fbas_for_rg("dir1");
S> print Dumper \%fba_ref;
S> =================================
S> I am wondering: Do I even need the locks for the hash reference,
Yes.
S> does this lock the entire hash, or solely the key in question?
The whole hash.
S> Does this still go faster?
Than what? I'm not sure what we're measuring.
Your code looks OK. You should probably destroy the hash in the main
process after the children are done. This is not showing all your code;
your initialization should have an ID for the shared memory segment
you're using. If you use the same ID, you will reuse the same space, so
you don't have to destroy it if you'll be reusing it regularly.
Sometimes people use the process ID $$ as the shared memory ID, and in
that case you'll keep allocating more memory every time.
Ted
------------------------------
Date: Tue, 23 Sep 2008 08:29:52 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: IPC:Shareable
Message-Id: <864p47f0rz.fsf@lifelogs.com>
On Mon, 22 Sep 2008 07:57:41 -0700 (PDT) Snorik <clauskick@hotmail.com> wrote:
S> I do the following now:
S> if ($pid)
S> {
S> push(@children, $pid);
S> }
S> elsif ($pid == 0)
S> {
S> use File::Find::Rule;
S> my @fbas = File::Find::Rule->file->in("/default/main/www/$rg/$gg/
S> WORKAREA/workarea/$gg_fba");
S> $ipc->lock(LOCK_EX);
S> $shared{$gg} = \@fbas;
S> $ipc->unlock();
S> exit (0);
S> }
S> else
S> {
S> print STDERR "\nERROR: fork failed: $!\n";
S> }
S> }
By the way, I forgot to mention: you can just put the file list in a
file, and have the file name in the shared memory. That way you get
locking (only the process with the shared memory lock can open or write
to files), your shared memory usage is low, and you don't have to worry
about serializing large amounts of data. This is what I've used in the
past for database loaders. It works well.
Ted
------------------------------
Date: Tue, 23 Sep 2008 07:37:55 -0700 (PDT)
From: Snorik <clauskick@hotmail.com>
Subject: Re: IPC:Shareable
Message-Id: <f8d7c918-d374-43ff-8f06-2d3dfbac42ca@i76g2000hsf.googlegroups.com>
On Sep 23, 3:29=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Mon, 22 Sep 2008 07:57:41 -0700 (PDT) Snorik <clausk...@hotmail.com> w=
rote:
>
> S> I do the following now:
>
> S> if ($pid)
> S> {
> S> push(@children, $pid);
> S> }
> S> elsif ($pid =3D=3D 0)
> S> {
> S> use File::Find::Rule;
> S> my @fbas =3D File::Find::Rule->file->in("/default/main/www/$rg/$gg/
> S> WORKAREA/workarea/$gg_fba");
> S> $ipc->lock(LOCK_EX);
> S> $shared{$gg} =3D \@fbas;
> S> $ipc->unlock();
> S> exit (0);
> S> }
> S> else
> S> {
> S> print STDERR "\nERROR: fork failed: $!\n";
> S> }
> S> }
>
> By the way, I forgot to mention: you can just put the file list in a
> file, and have the file name in the shared memory. =A0That way you get
> locking (only the process with the shared memory lock can open or write
> to files), your shared memory usage is low, and you don't have to worry
> about serializing large amounts of data. =A0This is what I've used in the
> past for database loaders. =A0It works well.
That is a good idea and what I am going to do!
------------------------------
Date: Tue, 23 Sep 2008 07:42:26 -0700 (PDT)
From: Snorik <clauskick@hotmail.com>
Subject: Re: IPC:Shareable
Message-Id: <5c8a508e-ecad-425e-ad21-13e5108702a6@f36g2000hsa.googlegroups.com>
On Sep 23, 3:27=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
> On Mon, 22 Sep 2008 07:57:41 -0700 (PDT) Snorik <clausk...@hotmail.com> w=
rote:
>
> S> if ($pid)
> S> {
> S> push(@children, $pid);
> S> }
> S> elsif ($pid =3D=3D 0)
> S> {
> S> use File::Find::Rule;
> S> my @fbas =3D File::Find::Rule->file->in("/default/main/www/$rg/$gg/
> S> WORKAREA/workarea/$gg_fba");
> S> $ipc->lock(LOCK_EX);
> S> $shared{$gg} =3D \@fbas;
> S> $ipc->unlock();
> S> exit (0);
> S> }
> S> else
> S> {
> S> print STDERR "\nERROR: fork failed: $!\n";
> S> }
> S> }
>
> S> foreach (@children)
> S> {
> S> waitpid($_, 0);
> S> }
> S> return %shared;
>
> S> And in the calling script:
>
> S> my %fba_ref =3D Package::get_fbas_for_rg("dir1");
> S> print Dumper \%fba_ref;
>
> S> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> S> I am wondering: Do I even need the locks for the hash reference,
>
> Yes.
>
> S> does this lock the entire hash, or solely the key in question?
>
> The whole hash.
>
> S> Does this still go faster?
>
> Than what? =A0I'm not sure what we're measuring. =A0
>
> Your code looks OK. =A0You should probably destroy the hash in the main
> process after the children are done. =A0
Ok, but how do I return it to the calling script otherwise?
The idea of all of this is to encapsulate the action completely and
just return something from the module without anyone having to bother
what happens inside there.
>This is not showing all your code;
> your initialization should have an ID for the shared memory segment
> you're using. =A0If you use the same ID, you will reuse the same space, s=
o
> you don't have to destroy it if you'll be reusing it regularly.
I just noticed that reusing it means that for a second run with other
parameters, I also receive part of the result from the first one. So,
I better not keep it :)
For initialization, I just use the following:
my $ipc =3D tie %shared, 'Tie::ShareLite', -key=3D>1971, -mode=3D>0600, -
create=3D>'yes', -destroy =3D>'no' or die("Could not tie to shared memory:
$!")
> Sometimes people use the process ID $$ as the shared memory ID, and in
> that case you'll keep allocating more memory every time.
I do not want to keep it, how can I clean it up properly (again,
hidden inside the module if possible) and still return a valid
reference from the routine in the module?
------------------------------
Date: Tue, 23 Sep 2008 08:15:16 -0700 (PDT)
From: Snorik <clauskick@hotmail.com>
Subject: Re: IPC:Shareable
Message-Id: <910b8086-46f5-4a9e-8045-e02cb02e77cd@a1g2000hsb.googlegroups.com>
On Sep 23, 4:42=A0pm, Snorik <clausk...@hotmail.com> wrote:
> On Sep 23, 3:27=A0pm, Ted Zlatanov <t...@lifelogs.com> wrote:
>
>
>
> > On Mon, 22 Sep 2008 07:57:41 -0700 (PDT) Snorik <clausk...@hotmail.com>=
wrote:
>
> > S> if ($pid)
> > S> {
> > S> push(@children, $pid);
> > S> }
> > S> elsif ($pid =3D=3D 0)
> > S> {
> > S> use File::Find::Rule;
> > S> my @fbas =3D File::Find::Rule->file->in("/default/main/www/$rg/$gg/
> > S> WORKAREA/workarea/$gg_fba");
> > S> $ipc->lock(LOCK_EX);
> > S> $shared{$gg} =3D \@fbas;
> > S> $ipc->unlock();
> > S> exit (0);
> > S> }
> > S> else
> > S> {
> > S> print STDERR "\nERROR: fork failed: $!\n";
> > S> }
> > S> }
>
> > S> foreach (@children)
> > S> {
> > S> waitpid($_, 0);
> > S> }
> > S> return %shared;
>
> > S> And in the calling script:
>
> > S> my %fba_ref =3D Package::get_fbas_for_rg("dir1");
> > S> print Dumper \%fba_ref;
>
> > S> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> > S> I am wondering: Do I even need the locks for the hash reference,
>
> > Yes.
>
> > S> does this lock the entire hash, or solely the key in question?
>
> > The whole hash.
>
> > S> Does this still go faster?
>
> > Than what? =A0I'm not sure what we're measuring. =A0
>
> > Your code looks OK. =A0You should probably destroy the hash in the main
> > process after the children are done. =A0
>
> Ok, but how do I return it to the calling script otherwise?
> The idea of all of this is to encapsulate the action completely and
> just return something from the module without anyone having to bother
> what happens inside there.
>
> >This is not showing all your code;
> > your initialization should have an ID for the shared memory segment
> > you're using. =A0If you use the same ID, you will reuse the same space,=
so
> > you don't have to destroy it if you'll be reusing it regularly.
>
> I just noticed that reusing it means that for a second run with other
> parameters, I also receive part of the result from the first one. So,
> I better not keep it :)
>
> For initialization, I just use the following:
>
> =A0my $ipc =3D tie %shared, 'Tie::ShareLite', -key=3D>1971, -mode=3D>0600=
, -
> create=3D>'yes', -destroy =3D>'no' or die("Could not tie to shared memory=
:
> $!")
>
> > Sometimes people use the process ID $$ as the shared memory ID, and in
> > that case you'll keep allocating more memory every time.
>
> I do not want to keep it, how can I clean it up properly (again,
> hidden inside the module if possible) and still return a valid
> reference from the routine in the module?
To illustrate, I want to do this (this is most of the calling script):
my %fba_ref =3D Package::get_fbas_for_rg("directory");
print Dumper \%fba_ref;
Trying to clear the memory like this (hardcoded id, I know, but if I
clear it everytime I use it it should not be a problem - right?):
Package::cleanMemory(1971);
returns a "permission denied" error.
cleanMemory just looks like this:
161 {
162 my $handle =3D shift;
163 use IPC::ShareLite;
164 my $share =3D IPC::ShareLite->new( -key =3D> $handle, -
create =3D> 'yes', -destroy =3D> 'no') or die "caution: ".$!;
165 $share->destroy();
166 }
I figured, I can just reuse the shared memory segment and just destroy
it - but I seem to be too dense to get that.
------------------------------
Date: Tue, 23 Sep 2008 22:18:21 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Regular express for <p>, <ul> and <ol> tags
Message-Id: <1222204693.2759.0@proxy00.news.clara.net>
> Unfortunately, your both in the same boat then.
s/your/you're/
> No offence.
Funny how people write that when they've deliberately offended.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 23 Sep 2008 22:24:52 +0100
From: Henry Law <news@lawshouse.org>
Subject: Re: Regular express for <p>, <ul> and <ol> tags
Message-Id: <1222205087.24944.0@proxy02.news.clara.net>
sln@netherlands.com wrote:
> Why do you even try to test me? What are you afraid of?
>
> sln/aka ROBIC0
... and then hundreds of lines of stuff ...
ROBIC0? All is clear now.
--
Henry Law Manchester, England
------------------------------
Date: Tue, 23 Sep 2008 12:22:29 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Replacing binary data containing & using perl in HPUX 11.11
Message-Id: <m13ajq25oa.fsf@dot-app.org>
badkmail@gmail.com writes:
> Using Perl, I want to search for a binary data containing & and
> alphabets and replace with another string. I am getting an error as
> put below:
>
> bash-3.2# echo fsdalf&l91Afjkdf | perl -p -e 's/l91A/l2A/g;'
> [1] 11326
> fsdalf
> bash: l91Afjkdf: command not found
> [1]+ Done echo fsdalf
> bash-3.2#
That's not a Perl error - bash is interpreting the & as the end of a
command. You need to quote shell command arguments that include things
like that:
sherm:~ sherm$ echo fsdalf&191Afjkdf | perl -p -e 's/191A/12A/g;'
[1] 11387
fsdalf
-bash: 191Afjkdf: command not found
[1]+ Done echo fsdalf
sherm:~ sherm$ echo "fsdalf&191Afjkdf" | perl -p -e 's/191A/12A/g;'
fsdalf&12Afjkdf
sherm--
--
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
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 1871
***************************************