[28885] in Perl-Users-Digest
Perl-Users Digest, Issue: 129 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 12 16:15:09 2007
Date: Mon, 12 Feb 2007 13:14:25 -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 Mon, 12 Feb 2007 Volume: 11 Number: 129
Today's topics:
bypass shell - pipe into child pid and receive otput <wahab-mail@gmx.de>
Re: bypass shell - pipe into child pid and receive otpu <spamtrap@dot-app.org>
Re: bypass shell - pipe into child pid and receive otpu <wahab-mail@gmx.de>
Re: bypass shell - pipe into child pid and receive otpu <spamtrap@dot-app.org>
Re: bypass shell - pipe into child pid and receive otpu <uri@stemsystems.com>
Re: bypass shell - pipe into child pid and receive otpu xhoster@gmail.com
Re: bypass shell - pipe into child pid and receive otpu xhoster@gmail.com
Re: bypass shell - pipe into child pid and receive otpu anno4000@radom.zrz.tu-berlin.de
Re: bypass shell - pipe into child pid and receive otpu <uri@stemsystems.com>
Re: bypass shell - pipe into child pid and receive otpu <nospam-abuse@ilyaz.org>
Re: bypass shell - pipe into child pid and receive otpu xhoster@gmail.com
Re: bypass shell - pipe into child pid and receive otpu <uri@stemsystems.com>
Re: bypass shell - pipe into child pid and receive otpu <spamtrap@dot-app.org>
Re: bypass shell - pipe into child pid and receive otpu <spamtrap@dot-app.org>
Concurrent Access FeelLikeANut@gmail.com
Re: Concurrent Access xhoster@gmail.com
Re: Concurrent Access <cwilbur@chromatico.net>
Re: Concurrent Access <ch.l.ngre@online.de>
form with no name <nospam@home.com>
Re: form with no name <glex_no-spam@qwest-spam-no.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 12 Feb 2007 11:31:33 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: bypass shell - pipe into child pid and receive otput
Message-Id: <eqpg02$aam$1@mlucom4.urz.uni-halle.de>
I'm trying to work with a filter prog
under Unix from a Perl script (CGI).
This program (htmldoc, => google) receives
some command line parameters and some input
via stdin - and returns its output via stdout.
What I do is: piping through the shell, like:
{
...
my $htmlpage = '... several KB HTML stuff, comes from above ';
my $prog = '/usr/bin/htmldoc';
return
qx{echo -e '$htmlpage' | $prog --webpage -t pdf -}
}
... and receive the output directly back to the Perl script.
This works somehow, BUT has tremendous security problems (imho).
How can I bypass the shell, maybe via
forking a child process, like:
<pseudo>
...
my $pid = open( my $pipe, "-|") or die "can't fork $!";
unless( $pid ) { # did we get 0 pid back?
exec $prog, $htmlpage
}
</pseudo>
But this wouldn't give me the output of $prog back.
What did I miss?
Thanks & regards
Mirco
------------------------------
Date: Mon, 12 Feb 2007 05:58:55 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <m2r6svd4ls.fsf@local.wv-www.com>
Mirco Wahab <wahab-mail@gmx.de> writes:
> I'm trying to work with a filter prog
> under Unix from a Perl script (CGI).
>
> This program (htmldoc, => google) receives
> some command line parameters and some input
> via stdin - and returns its output via stdout.
So what you want is to write to this program's STDIN, and at the same time
read from its STDOUT?
If so, have a look at IPC::Open2. Or, if you want to handle STDERR as well,
IPC::Open3. Both are core modules, so you should have them already.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 12 Feb 2007 13:46:54 +0100
From: Mirco Wahab <wahab-mail@gmx.de>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <eqpntr$chr$1@mlucom4.urz.uni-halle.de>
Sherm Pendley wrote:
>> I'm trying to work with a filter prog
>> under Unix from a Perl script (CGI).
>>
>> This program (htmldoc, => google) receives
>> some command line parameters and some input
>> via stdin - and returns its output via stdout.
>
> So what you want is to write to this program's STDIN, and at the same time
> read from its STDOUT?
>
> If so, have a look at IPC::Open2. Or, if you want to handle STDERR as well,
> IPC::Open3. Both are core modules, so you should have them already.
Thanks, I have been running into some
problems with that. Lets consider:
# actual production code :-((
sub makepdf {
my $ht = shift;
...
...
my $prog = '/usr/bin/htmldoc';
my @args = qw' --webpage --quiet -t pdf14 ';
if(1) { # this works o.k. after removing \' from the html stream
return qx{echo -e '$ht' | $prog @args -}
}
else { # this will wait forever
use IPC::Open2;
my($chld_out, $chld_in);
my $childpid = open2($chld_out, $chld_in, $prog, @args)
or die "can't open pipe to $prog: $!";
print $chld_in $ht;
close $chld_in;
my $pdf; do { local $/; $pdf = <$chld_out> };
close $chld_out;
waitpid $childpid, 0;
return $pdf;
}
}
What happens is (after I change "if(1) to if(0)"):
the pipe to the program is opened, then the
(this) program does noting. It just sits and
waits.
Maybe I'll write a litte C program to inspect what
happens there.
Hmmm. Still trying ...
Regards & Thanks
Mirco
------------------------------
Date: Mon, 12 Feb 2007 08:40:21 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <m2k5yncx4q.fsf@local.wv-www.com>
Mirco Wahab <wahab-mail@gmx.de> writes:
> Thanks, I have been running into some
> problems with that. Lets consider:
>
> # actual production code :-((
>
> sub makepdf {
> my $ht = shift;
> ...
> ...
> my $prog = '/usr/bin/htmldoc';
> my @args = qw' --webpage --quiet -t pdf14 ';
>
> if(1) { # this works o.k. after removing \' from the html stream
> return qx{echo -e '$ht' | $prog @args -}
> }
> else { # this will wait forever
> use IPC::Open2;
> my($chld_out, $chld_in);
> my $childpid = open2($chld_out, $chld_in, $prog, @args)
> or die "can't open pipe to $prog: $!";
> print $chld_in $ht;
> close $chld_in;
> my $pdf; do { local $/; $pdf = <$chld_out> };
> close $chld_out;
> waitpid $childpid, 0;
> return $pdf;
> }
> }
>
>
> What happens is (after I change "if(1) to if(0)"):
> the pipe to the program is opened, then the
> (this) program does noting. It just sits and
> waits.
Well, this isn't really a filter program. I looked at the docs for it online,
and there doesn't seem to be any provision to tell it to accept its input from
STDIN, only for passing a filename. Passing '-' as the filename works as a
shell command, but that's the shell's doing, not htmldoc's.
When you pass $prog and @args separately, you're bypassing the shell argument
processing, so the '-' filename isn't working.
You could allow the shell to process the command arguments, by passing $prog =
'/usr/bin/htmldoc --webpage --quiet -t pdf14 -', and no @args array. Since
all of the arguments you're passing are constants, nothing from the fetched
page, there's no harm in letting the shell parse the arguments.
If that still doesn't work, you might also try it with $prog = '/bin/sh -c
/usr/bin/htmldoc --webpage --quiet -t pdf14 -', and nothing in @args.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 12 Feb 2007 11:07:16 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <x7bqjzxsuj.fsf@mail.sysarch.com>
>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:
SP> Well, this isn't really a filter program. I looked at the docs for
SP> it online, and there doesn't seem to be any provision to tell it
SP> to accept its input from STDIN, only for passing a
SP> filename. Passing '-' as the filename works as a shell command,
SP> but that's the shell's doing, not htmldoc's.
the shell never handles - by itself. just like perl does, it is a
convention that many programs support a filename of - to mean stdin (or
stdout). the shell only handles > and < and << itself for file
redirection.
SP> When you pass $prog and @args separately, you're bypassing the
SP> shell argument processing, so the '-' filename isn't working.
that doesn't matter. the question is whether htmldoc processes a
filename of - to mean stdin.
SP> If that still doesn't work, you might also try it with $prog = '/bin/sh -c
SP> /usr/bin/htmldoc --webpage --quiet -t pdf14 -', and nothing in @args.
that still uses a shell which he is trying to avoid.
i browsed the docs of htmldoc and i found nothing that lets it read from
stdin. it seems to require a real input file (or more than one). it will
print to stdout if no output option is used. so it seems the OP is stuck
with calling qx (or maybe open |-) with a real file for input.
one option would be to use a temp file and file::slurp to write it out
before the call to htmldoc.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: 12 Feb 2007 16:17:39 GMT
From: xhoster@gmail.com
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <20070212111827.848$bV@newsreader.com>
Mirco Wahab <wahab-mail@gmx.de> wrote:
> I'm trying to work with a filter prog
> under Unix from a Perl script (CGI).
>
> This program (htmldoc, => google) receives
> some command line parameters and some input
> via stdin - and returns its output via stdout.
>
> What I do is: piping through the shell, like:
>
> {
> ...
> my $htmlpage = '... several KB HTML stuff, comes from above ';
> my $prog = '/usr/bin/htmldoc';
>
> return
> qx{echo -e '$htmlpage' | $prog --webpage -t pdf -}
> }
>
> ... and receive the output directly back to the Perl script.
> This works somehow, BUT has tremendous security problems (imho).
What are those problems, IYHO?
>
> How can I bypass the shell, maybe via
> forking a child process, like:
>
> <pseudo>
> ...
> my $pid = open( my $pipe, "-|") or die "can't fork $!";
> unless( $pid ) { # did we get 0 pid back?
> exec $prog, $htmlpage
> }
> </pseudo>
>
> But this wouldn't give me the output of $prog back.
Well of course it wouldn't. Perl is a language, not a psuedo-language.
> What did I miss?
See above.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 12 Feb 2007 16:29:03 GMT
From: xhoster@gmail.com
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <20070212112952.408$6f@newsreader.com>
Mirco Wahab <wahab-mail@gmx.de> wrote:
> Sherm Pendley wrote:
> >> I'm trying to work with a filter prog
> >> under Unix from a Perl script (CGI).
> >>
> >> This program (htmldoc, => google) receives
> >> some command line parameters and some input
> >> via stdin - and returns its output via stdout.
> >
> > So what you want is to write to this program's STDIN, and at the same
> > time read from its STDOUT?
> >
> > If so, have a look at IPC::Open2. Or, if you want to handle STDERR as
> > well, IPC::Open3. Both are core modules, so you should have them
> > already.
>
> Thanks, I have been running into some
> problems with that. Lets consider:
>
> # actual production code :-((
>
> sub makepdf {
> my $ht = shift;
> ...
> ...
> my $prog = '/usr/bin/htmldoc';
> my @args = qw' --webpage --quiet -t pdf14 ';
>
> if(1) { # this works o.k. after removing \' from the html stream
> return qx{echo -e '$ht' | $prog @args -}
> }
> else { # this will wait forever
> use IPC::Open2;
> my($chld_out, $chld_in);
> my $childpid = open2($chld_out, $chld_in, $prog, @args)
> or die "can't open pipe to $prog: $!";
In the qx you have "-" in the argument list but in the open2 you don't.
If it is needed in one place, I don't see why it wouldn't be in the other.
I'd think you would see an error message if no input is given, but maybe
the --quiet hides it.
> print $chld_in $ht;
> close $chld_in;
> my $pdf; do { local $/; $pdf = <$chld_out> };
You may have a buffering/deadlock problem here, assuming $prog starts
producing output before it completely reads its input. You could use
IO::Select on $chld_in and $chld_out to get around this. Or you could
do another fork, and have one branch do the "print $chld_in $ht; exit;"
and the other branch do the read from $chld_out.
> close $chld_out;
> waitpid $childpid, 0;
Doesn't the close automatically call wait for you?
> return $pdf;
> }
> }
>
> What happens is (after I change "if(1) to if(0)"):
> the pipe to the program is opened, then the
> (this) program does noting. It just sits and
> waits.
>
> Maybe I'll write a litte C program to inspect what
> happens there.
If you are linux, it is easier to strace it and see what system
call, if any, it is waiting on.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 12 Feb 2007 16:48:24 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <53bk2oF1rhl7bU1@mid.dfncis.de>
Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
[...]
> i browsed the docs of htmldoc and i found nothing that lets it read from
> stdin. it seems to require a real input file (or more than one). it will
> print to stdout if no output option is used. so it seems the OP is stuck
> with calling qx (or maybe open |-) with a real file for input.
>
> one option would be to use a temp file and file::slurp to write it out
> before the call to htmldoc.
Either that or a named pipe (OS permitting).
Anno
------------------------------
Date: Mon, 12 Feb 2007 12:06:25 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <x7tzxrwbji.fsf@mail.sysarch.com>
>>>>> "a" == anno4000 <anno4000@radom.zrz.tu-berlin.de> writes:
a> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
a> [...]
>> i browsed the docs of htmldoc and i found nothing that lets it read from
>> stdin. it seems to require a real input file (or more than one). it will
>> print to stdout if no output option is used. so it seems the OP is stuck
>> with calling qx (or maybe open |-) with a real file for input.
>>
>> one option would be to use a temp file and file::slurp to write it out
>> before the call to htmldoc.
a> Either that or a named pipe (OS permitting).
that is an option i rarely think about but yes, it could work. the
problem is that it will need to be a unique name for each web access to
make sure it doesn't collide with other hits. usually named pipes are
somewhat permanent and they can be shared for input. a real temp file
seems to be a simpler and more portable solution. or contact the authors
of the program and have them support reading from stdin. it is a paid
program so they should respond to such a request.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 12 Feb 2007 17:18:03 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <eqq7gb$v7t$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Uri Guttman
<uri@stemsystems.com>], who wrote in article <x7bqjzxsuj.fsf@mail.sysarch.com>:
> i browsed the docs of htmldoc and i found nothing that lets it read from
> stdin. it seems to require a real input file (or more than one). it will
> print to stdout if no output option is used. so it seems the OP is stuck
> with calling qx (or maybe open |-) with a real file for input.
With contemporary Unices one could use something like /proc/self/stdin (sp?).
Hope this helps,
Ilya
------------------------------
Date: 12 Feb 2007 17:40:03 GMT
From: xhoster@gmail.com
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <20070212124052.675$iN@newsreader.com>
Uri Guttman <uri@stemsystems.com> wrote:
> >>>>> "a" == anno4000 <anno4000@radom.zrz.tu-berlin.de> writes:
>
> a> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
> a> [...]
>
> >> i browsed the docs of htmldoc and i found nothing that lets it read
> >> from stdin. it seems to require a real input file (or more than
> >> one). it will print to stdout if no output option is used. so it
> >> seems the OP is stuck with calling qx (or maybe open |-) with a real
> >> file for input.
> >>
> >> one option would be to use a temp file and file::slurp to write it
> >> out before the call to htmldoc.
>
> a> Either that or a named pipe (OS permitting).
>
> that is an option i rarely think about but yes, it could work. the
> problem is that it will need to be a unique name for each web access to
> make sure it doesn't collide with other hits. usually named pipes are
> somewhat permanent and they can be shared for input. a real temp file
> seems to be a simpler and more portable solution. or contact the authors
> of the program and have them support reading from stdin.
Am I missing something, or doesn't it already support reading from stdin?
The qx, after all, causes it to do just that.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 12 Feb 2007 13:05:04 -0500
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <x7ire7w8tr.fsf@mail.sysarch.com>
>>>>> "x" == xhoster <xhoster@gmail.com> writes:
x> Uri Guttman <uri@stemsystems.com> wrote:
>> >>>>> "a" == anno4000 <anno4000@radom.zrz.tu-berlin.de> writes:
>>
a> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
a> [...]
>>
>> >> i browsed the docs of htmldoc and i found nothing that lets it read
>> >> from stdin. it seems to require a real input file (or more than
>> >> one). it will print to stdout if no output option is used. so it
>> >> seems the OP is stuck with calling qx (or maybe open |-) with a real
>> >> file for input.
>> >>
>> >> one option would be to use a temp file and file::slurp to write it
>> >> out before the call to htmldoc.
>>
a> Either that or a named pipe (OS permitting).
>>
>> that is an option i rarely think about but yes, it could work. the
>> problem is that it will need to be a unique name for each web access to
>> make sure it doesn't collide with other hits. usually named pipes are
>> somewhat permanent and they can be shared for input. a real temp file
>> seems to be a simpler and more portable solution. or contact the authors
>> of the program and have them support reading from stdin.
x> Am I missing something, or doesn't it already support reading from stdin?
x> The qx, after all, causes it to do just that.
well, the OP hasn't reported back but as i said, the docs don't seem to
support reading from stdin. maybe the OP was mistaken about it working
that way (he echoed the filename in which is very odd).
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Mon, 12 Feb 2007 15:42:21 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <m2fy9bcdle.fsf@local.wv-www.com>
Uri Guttman <uri@stemsystems.com> writes:
>>>>>> "SP" == Sherm Pendley <spamtrap@dot-app.org> writes:
>
>
> SP> Well, this isn't really a filter program. I looked at the docs for
> SP> it online, and there doesn't seem to be any provision to tell it
> SP> to accept its input from STDIN, only for passing a
> SP> filename. Passing '-' as the filename works as a shell command,
> SP> but that's the shell's doing, not htmldoc's.
>
> the shell never handles - by itself. just like perl does, it is a
> convention that many programs support a filename of - to mean stdin (or
> stdout). the shell only handles > and < and << itself for file
> redirection.
Oh, sorry - bad assumption on my part then.
Mirco's version which used qx[] used '-' as the input filename. It worked,
but used an "echo '$input'" to provide the input to htmldoc's stdin. I
assumed the '-' worked because of shell expansion, and that he'd omitted
it from the open2() version because he was using the multi-arg form and
bypassing the shell.
If, as you say, passing '-' directly to htmldoc would have worked, then
the most likely reason that the open2() version failed was because that
version didn't do that. It didn't get any input, so didn't produce any
output.
> SP> When you pass $prog and @args separately, you're bypassing the
> SP> shell argument processing, so the '-' filename isn't working.
>
> that doesn't matter. the question is whether htmldoc processes a
> filename of - to mean stdin.
It processed it when he used it via qx[].
That being the case, I'd say that his open2() version failed because he
didn't supply the '-' filename argument to that one.
> SP> If that still doesn't work, you might also try it with $prog = '/bin/sh -c
> SP> /usr/bin/htmldoc --webpage --quiet -t pdf14 -', and nothing in @args.
>
> that still uses a shell which he is trying to avoid.
I thought he was trying to avoid the specific use of "echo '$huge_html'",
not the shell in general. That's a lot of input for the shell to parse,
even if it's just finding the end quote, and for some shells might even
exceed the maximum length of a command. It's not a very clean way to provide
htmldoc with input on its stdin.
Feeding unaltered input directly to htmldoc's stdin seems IMHO to be a
cleaner approach than using echo to do it. It's just that the devil, as the
saying goes, is in the details. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Mon, 12 Feb 2007 15:47:52 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: bypass shell - pipe into child pid and receive otput
Message-Id: <m2bqjzcdc7.fsf@local.wv-www.com>
xhoster@gmail.com writes:
> Mirco Wahab <wahab-mail@gmx.de> wrote:
>
>> print $chld_in $ht;
>> close $chld_in;
>> my $pdf; do { local $/; $pdf = <$chld_out> };
>
> You may have a buffering/deadlock problem here, assuming $prog starts
> producing output before it completely reads its input.
I'm not certain that's a valid assumption in this case. The job of this
program is to take HTML input and produce PDF output. I don't think it
could do that without first reading all of its input. One can, for example,
include an inline style attribute on the very last p element in the HTML
body, that positions it at the top of the rendered page.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 11 Feb 2007 18:56:23 -0800
From: FeelLikeANut@gmail.com
Subject: Concurrent Access
Message-Id: <1171248983.335540.281420@m58g2000cwm.googlegroups.com>
When you need to update a value in a file, it's pretty simple: lock
exclusively, read the value, manipulate it, write it, and release the
lock. I'm not sure how this world work with an SQL database, however.
I can use the select statement to read the value and the update
statement to write the value, but how do I make sure that the value
isn't tampered with between those two statements?
------------------------------
Date: 12 Feb 2007 03:51:51 GMT
From: xhoster@gmail.com
Subject: Re: Concurrent Access
Message-Id: <20070211225237.955$kv@newsreader.com>
FeelLikeANut@gmail.com wrote:
> When you need to update a value in a file, it's pretty simple: lock
> exclusively, read the value, manipulate it, write it, and release the
> lock. I'm not sure how this world work with an SQL database, however.
> I can use the select statement to read the value and the update
> statement to write the value, but how do I make sure that the value
> isn't tampered with between those two statements?
That depends on what database engine you use.
Also, it has nearly nothing to do with Perl.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 11 Feb 2007 23:01:27 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Concurrent Access
Message-Id: <878xf4nhwo.fsf@mithril.chromatico.net>
>>>>> "FLAN" == FeelLikeANut <FeelLikeANut@gmail.com> writes:
FLAN> I can use the select statement to read the value and the
FLAN> update statement to write the value, but how do I make sure
FLAN> that the value isn't tampered with between those two
FLAN> statements?
This has more to do with databases than with Perl, and in particular
with your choice of databases; but the answer is generally either
transactions, table locking, or sensible database schema design.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Mon, 12 Feb 2007 14:34:44 +0100
From: Ch Lamprecht <ch.l.ngre@online.de>
Subject: Re: Concurrent Access
Message-Id: <eqpqdi$b9a$1@online.de>
FeelLikeANut@gmail.com wrote:
> When you need to update a value in a file, it's pretty simple: lock
> exclusively, read the value, manipulate it, write it, and release the
> lock. I'm not sure how this world work with an SQL database, however.
> I can use the select statement to read the value and the update
> statement to write the value, but how do I make sure that the value
> isn't tampered with between those two statements?
>
Search your database docs:
SELECT ..... FOR UPDATE
does a row level lock for the current transaction e.g. in Postgresql, but I
think it's standard SQL.
Christoph
--
push @INC , sub{*DATA};
require JaPH;
__END__
print 'Just another Perl Hacker'
------------------------------
Date: Sun, 11 Feb 2007 19:13:41 GMT
From: "Nospam" <nospam@home.com>
Subject: form with no name
Message-Id: <FVJzh.16818$wP3.14441@newsfe7-gui.ntli.net>
I am looking at the html for this particular form field, I notice it doesn't
have a name as such, since it is dynamic each time you reload the page, the
only contant I can see is id="Title" but I don't see a format for an
undefined field that isn't name or value in www::mechanize
The relevant html is:
<input tabindex="1" type="text" size="50" maxlength="70"
name="U2FsdGVkX1_e8Buy3gSEbKFvuhmg44zfhnDmuwGG_REhETDSW48VUzUHAIySM35YWxvtxG
XqHSbdcPnoaAwMkg" id="Title" value=""><br>
so far I have tried:
$mech->current_form();
...
$mech->form_number(1); //incidentally it's the only form on the page, but
for some reason doesn't acknowledge anything
------------------------------
Date: Mon, 12 Feb 2007 10:52:34 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: form with no name
Message-Id: <45d09b1f$0$10307$815e3792@news.qwest.net>
Nospam wrote:
> I am looking at the html for this particular form field, I notice it doesn't
> have a name as such, since it is dynamic each time you reload the page, the
> only contant I can see is id="Title" but I don't see a format for an
> undefined field that isn't name or value in www::mechanize
It does have a 'name' element, but you have to find that dynamically.
>
> The relevant html is:
>
> <input tabindex="1" type="text" size="50" maxlength="70"
> name="U2FsdGVkX1_e8Buy3gSEbKFvuhmg44zfhnDmuwGG_REhETDSW48VUzUHAIySM35YWxvtxG
> XqHSbdcPnoaAwMkg" id="Title" value=""><br>
>
> so far I have tried:
>
> $mech->current_form();
> ...
>
> $mech->form_number(1); //incidentally it's the only form on the page, but
> for some reason doesn't acknowledge anything
And what did they return?
use Data::Dumper;
...
my $form = $mech->current_form();
print Dumper( $form );
It should return an HTML::Form object. It looks like
it could be parsed/used to find the "name" where the id is
'Title', for an input element, then you could use
that with your WWW::Mechanize object.
perldoc HTML::Form
------------------------------
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 129
**************************************