[21807] in Perl-Users-Digest
Perl-Users Digest, Issue: 4011 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 22 21:05:53 2002
Date: Tue, 22 Oct 2002 18:05:11 -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 Oct 2002 Volume: 10 Number: 4011
Today's topics:
alarm interfering with LWP::Request (David Keeney)
Re: alarm interfering with LWP::Request <goldbb2@earthlink.net>
Re: Assigning one symbol table to another one <bobesch@letras.net>
database search trouble (Grant)
Re: deleting a file... kill ??? (Michael Puskar)
Re: format to output <wksmith@optonline.net>
Grab blob and DBH->quote()??? <zmonteca@zmonteca.com>
Re: Hiding password variables in PERL (Shelby)
Re: Hiding password variables in PERL (Shelby)
Re: How does @EXPORT function in a package? <mgjv@tradingpost.com.au>
NEWBIE foreach problem <tech@REMOVETOMAILall-in-one-business.com>
Re: open(STDOUT, ">/dev/null") successful but still get <goldbb2@earthlink.net>
perl DBI and prepared statements <bryan@akanta.com>
Re: perl DBI and prepared statements <goldbb2@earthlink.net>
Re: perl DBI and prepared statements <rereidy@indra.com>
Re: Perl Program <mgjv@tradingpost.com.au>
Running Perl through cron (LiquidPHP)
Re: Running Perl through cron <johngnub@worldnet.att.net>
Re: Running Perl through cron <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 22 Oct 2002 14:46:41 -0700
From: dkeeney@travelbyroad.net (David Keeney)
Subject: alarm interfering with LWP::Request
Message-Id: <4c1b9685.0210221346.62af99cc@posting.google.com>
I need to use alarm in the same script with LWP, and I find that
the alarm function causes the LWP fetch operation to abort. Is there
a workaround to this problem?
Here is a demonstration script: The timer handler just outputs a notice
and disables the alarm. That would seem to have no involvement with the
LWP operation.
=============== code follows ==========
use IO;
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$url = 'http://www.mapsonus.com/';
$SIG{ALRM} = \&gotcha;
sub gotcha {
print "gotcha \n";
alarm(0);
}
$ua->timeout(5);
# we have relatively recent versions
print "IO version [ $IO::VERSION ] \n"; # 1.20
print "IO::Socket version [ $IO::Socket::VERSION ] \n"; # 1.26
##### test 1
alarm(4);
print "alarm is 4 \n";
$request = HTTP::Request->new('GET', $url);
$response = $ua->request($request);
if ( $response->is_success ) {
print "success!!\n"
}
else {
print "error: ", $response->message, "\n";
}
#### test 2
alarm(1);
print "alarm is 1 \n";
$request = HTTP::Request->new('GET', $url);
$response = $ua->request($request);
if ( $response->is_success ) {
print "success!!\n";
}
else {
print "error: ", $response->message, "\n";
}
========================================
The resulting output is:
]$ perl prob_demo.pl
IO version [ 1.20 ]
IO::Socket version [ 1.26 ]
alarm is 4
success!!
alarm is 1
gotcha
error: read timeout
===========================================
I have run this test several times, and have ried reversing
the test order, and the timeout error is apparently a consequence
of the alarm signal.
Any insight you folks can provide me is appreciated.
David Keeney
dkeeney@travelbyroad.net
------------------------------
Date: Tue, 22 Oct 2002 18:49:02 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: alarm interfering with LWP::Request
Message-Id: <3DB5D5DE.9A1E5BBB@earthlink.net>
David Keeney wrote:
>
> I need to use alarm in the same script with LWP, and I find that
> the alarm function causes the LWP fetch operation to abort. Is there
> a workaround to this problem?
Disable the alarm, perform the lwp request, re-enable the alarm.
Eg:
my $time_remaining = alarm(0);
my $time = time;
$ua->timeout($time_remaining);
$response = $ua->request($request);
if( $time_remaining ) { # if an alarm had been set.
$time_remaining -= ( time() - $time );
if( $time_remaining > 0 ) { # either re-enable it.
alarm($time_remaining);
} else { # or if it would have expired, raise ALRM.
kill ALRM => $$;
}
}
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 23 Oct 2002 00:54:39 +0200
From: Bodo Schulze <bobesch@letras.net>
Subject: Re: Assigning one symbol table to another one
Message-Id: <87vg3uulsg.fsf@letras.net>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> Bodo Schulze wrote:
> >
> > Hi,
> >
> > symbol tables being stored in hashes, I wonder why it is not possible
> > to assign them using the normal hash syntax
> >
> > %hash1 = %hash2;
> >
> > On the other hand, it is possible to do the assignment like this
> >
> > @hash1{ keys %hash2 } = values %hash2;
>
> Symbol table hashes are slightly (or maybe very) magical. There's
> probably some optomization which prevents you from doing what you want.
>
> How about you try putting the assignment into a BEGIN block?
>
> BEGIN { %pkg2:: = %pkg1:: }
>
Thank you for your kind answer, Benjamin. I tested your proposition
and it works ok, but there are problems with assigning to %main:: as
Tassilo noted elsewhere in this thread. Anyway I don't have the intent
to use this sort of symbol table manipulation, since it's fine to have
different namespaces. I just played around with it for learning
purposes und felt intrigued by what seemed a strange behaviour to
me. Thanks again for the lesson you told me concerning BEGIN.
Best regards, Bodo
------------------------------
Date: Tue, 22 Oct 2002 14:23:04 -0400
From: "Compton, G. (Grant)" <gcompton@ford.com>
Subject: database search trouble
Message-Id: <3DB59788.89EC02E6@ford.com>
Hi all. I Hope that I'm not violating any etiquette here but I
need some help. I've been juggling this for many days now and
can't get it "just right". Maybe one or more of you can help me
get this to work properly.
I want to search a database file by 6 attributes.
The 6th being a search of 6 specific fields in the database
to see if any of them have the value 1.
A typical record might look like this:
asupplier|aprogram|acommodity|auser|asupervisor|5|3|3|5|3|1
5 is the highest number (best score)
3 is the acceptalble value
1 means unacceptable.
The search.html has default values set to "Select" & "All". I
change those to wildcards so that all records are printed if
those defaults are passed.
I also have a set of two radio buttons for "red issue". radio
button one = "2"(search only for records w/red issues) and button
two = 6 (show me all records regardless if they are "red". See
below... I use "<" in the search)
#!/usr/bin/perl
require "cgi-lib.pl";
$match="no";
#$redissue=2; #yes show me just records w/evaluations that are
unacceptable
#$redissue=6; #no show me all records regardless of evaluations
value
&ReadParse;
#change "Select"
#(the default from the dropdown menu on the web page)
#to wild cards
#this seems to be working fine
$in{'Supp'} =~ s/Select/.*./;
$in{'program'} =~ s/Select/.*./;
$in{'Comm'} =~ s/Select/.*./;
$in{'supervisorID'} =~ s/Select/.*./;
#if $revBy is "All" (default of the textarea on the web page)
#change it to wild cards. This one doesn't work as it should.
#I want an exact match if not "All" otherwise I want all
#records to return true for this. All revBy's in the database are
lowercase.
$in{'revBy'} =~ s/All/.*./;
open(FILE,"database.txt") || die "Can't find the database\n";
#store contents and close the file
@indata = <FILE>;
close(FILE);
print &PrintHeader;
#print the beginning of the results page
print <<"PrintTag";
<html>
<head>
<title>Search Results</title>
</head>
<body>
<table border="1" cellpadding="2" cellspacing="0">
<tr>
<td>Supplier</td>
<td>Program</td>
<td>Commodity</td>
<td>Revised By</td>
<td>Supervisor</td>
<td>Evaluation1</td>
<td>Evaluation2</td>
<td>Evaluation3</td>
<td>Evaluation4</td>
<td>Evaluation5</td>
<td>Evaluation6</td>
</tr>
PrintTag
foreach $i (@indata)
{
chomp($i);
($Supp,
$program,
$Comm,
$revBy,
$supervisorID,
$Evaluation1,
$Evaluation2,
$Evaluation3,
$Evaluation4,
$Evaluation5,
$Evaluation6,) = split(/\|/,$i);
if
(($Supp=~/$in{'Supp'}/i)&&
($program=~/$in{'program'}/i)&&
($Comm=~/$in{'Comm'}/i)&&
($supervisorID=~/$in{'supervisorID'}/i)&&
($revBy eq $in{revBy})&&
(($Evaluation1,
$Evaluation1,
$Evaluation2,
$Evaluation3,
$Evaluation4,
$Evaluation5,
$Evaluation6) < $in{'redissue'}))
{
$match="yes";
print "<tr align=center valign=center>\n";
print "<td>$Supp</td>";
print "<td>$program</td>";
print "<td>$Comm</td>";
print "<td>$revBy</td>";
print "<td>$supervisorID</td>";;
print "<td>$Evaluation1</td>";
print "<td>$Evaluation2</td>";
print "<td>$Evaluation3</td>";
print "<td>$Evaluation4</td>";
print "<td>$Evaluation5</td>";
print "<td>$Evaluation6</td>";
print "</tr>\n";
} #close the loop
}#close the table
print "</table>";
#if no matches are found print error
if ($match eq "no")
{
print <<"PrintErrorPage";
<html><head>
<title>Search Failed</title>
</head>
<body>
<p>No Matches Found. Please <a href=search.htm>try
again.</a></font></body>
</html>
PrintErrorPage
}
#end of program
Again I hope I have not alienated anybody with this long post but
I've been doing my homework and just can't get this to work
properly.
Please contact me directly if you don't understand my intent.
Thanks,
Grant
------------------------------
Date: 22 Oct 2002 13:50:20 -0700
From: puskarm@eighth-avenue.com (Michael Puskar)
Subject: Re: deleting a file... kill ???
Message-Id: <3e7726f4.0210221250.40899e6a@posting.google.com>
kill is for sending a signal to a process, not neccessarily to kill
it.... HUP is a good non-example
Anyway, as pointed out, unlink is the way to go...
Josef ?iso-8859-1?Q?M llers? <josef.moellers@fujitsu-siemens.com> wrote in message news:<3DB5619C.E8D12C68@fujitsu-siemens.com>...
> Helgi Briem wrote:
> >
>
> > On Tue, 22 Oct 2002 13:56:36 GMT, "G.Doucet"
> > <gldouce@nbnet.nb.ca> wrote:
> >
>
> > >I was updating a perl script that I wrote last year. The Perl script
> > >reads and writes to a few database files which are just simple text
> > >files. At one point, the perl script deletes an old file which goes
> > >something like this:
> > >
> > > if(-e "$obidfil"){kill $obidfil;}
> > >
> > <SNIP>
> >
>
> > kill is for stopping processes, not deleting files.
> > Your statement above will never do anything.
>
> Never say never:
>
> sub termproc ($) {
> my $obidfil = shift;
>
> chdir "/proc";
> if(-e "$obidfil"){kill $obidfil;}
> }
------------------------------
Date: Tue, 22 Oct 2002 21:19:47 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: format to output
Message-Id: <Thjt9.5374$Z9.2370@news4.srv.hcvlny.cv.net>
"Christian Caron" <nospam@nospam.org> wrote in message
news:ap3qie$3nj4@nrn2.NRCan.gc.ca...
>
--snip--
> Ok, your solution involves manual tinkering, but what if there are four
> lines instead of 3 because arrays are created dynamically? It needs to be
> automatic.
If there are only two cases, you could write formats for each and set the
appropriate format before each write.
>
> I found this solution (make variable an array, and loop for each line):
>
> #############
> #!/usr/bin/perl -w
>
> use strict;
>
> my @array1 = ("array1_one");
> my @array2 = ("array2_one","array2_two","array2_three");
> my @array3 = ("array3_one","array3_two");
>
> # Find the longest array and assign its length to $v
> # which I'm sure there's a solution that I'll find later...
> # For the moment, I know it's @array2
> my $array2_length = @array2;
> my $v = $array2_length;
> my $t;
>
> for $t (0 .. $v) {
> if (! $array1[$t]) {
> $array1[$t] = " ";
> }
> if (! $array2[$t]) {
> $array2[$t] = " ";
> }
> if (! $array3[$t]) {
> $array3[$t] = " ";
> }
> write;
> }
>
> format STDOUT =
> @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<
> $array1[$t], $array2[$t], $array3[$t]
> .
> #############
>
> Prints out:
>
> colargol# perl test.pl
> array1_one array2_one array3_one
> array2_two array3_two
> array2_three
>
You are correct, it does work, at least for some version of perl.
> Why do you recommend not to use format/write?
>
>
The write/format command is very convenient for displaying long tables with
a fixed format. It automatically places column headers at the start of
every page. However, it usually takes more work to handle special cases than
what you save over using printf. The documentation in perldoc perlform is
not nearly as complete as we have come to expect from the rest of perl.
Experiments are often needed to find out exactly what happens with undef
data, excessive data, null strings, data that overflows its format field,
word wrap in any column but the last, or whatever.
Good Luck,
Bill
------------------------------
Date: 22 Oct 2002 23:41:59 GMT
From: Z Monteca <zmonteca@zmonteca.com>
Subject: Grab blob and DBH->quote()???
Message-Id: <ap4no7$kkj$1@bob.news.rcn.net>
In the below code, I am trying grab a picture (data blob) from MySQL DB.
The objective of this is to call this from the 'img' tag in a form I made.
The problem is that I can NOT get this to appear as an IMAGE. For some
reason only the "Content-Type: image/jpeg\n\n$RAW-DATA" comes up. Anyone
have a clue what I am doing wrong?
Also, in storing this in the DB I use the 'dbh->quote($rawdata)', what is
the point of using this? Why can't I just insert $rawdata without quoting
it? If I must use the quote handle before inserting into the DB do I have
to unquote the quoted $rawdata before trying to use it to display it as an
image?
Thanks in advance....
-Zach
######################################################
##
if($I{F}{id}){
my @blob = sqlSelect('picture', 'static', 'indx=' . $I{F}{id});
my $data = $blob[0];
if (!$data){
print "Content-type: text/plain\n\n";
print "No data found. \n";
}
else{
#while(@blob) {
print "Content-Type: image/jpeg\n\n";
print STDOUT $blob[0];
#}
#print "Content-type: image/gif\n\n";
#print "$data";
}
}
else{
print "Content-type: text/plain\n\n";
print "Can't access script!\n";
}
exit(0);
------------------------------
Date: 22 Oct 2002 15:10:55 -0700
From: webmaster@smwebdesigns.com (Shelby)
Subject: Re: Hiding password variables in PERL
Message-Id: <ed11fbd8.0210221410.53995c39@posting.google.com>
Did you think about embeding it in your decrypt/encrypt files and then
when done just set each variable to null so that anyone using it
couldn't alter the mail.pl code to list out each variable. Let me
know if this works.
Shelby
webmaster@smwebdesigns.com
marcjgpelletier@hotmail.com (Marc Pelletier) wrote in message news:<96f58607.0210220658.1a037ce5@posting.google.com>...
> Alright, so here's the scoop .. wondering if anyone has ever come
> across something like this. Looking for any advice or workarounds as
> well.
>
> I have a main PERL script (call it main.pl) which reads a
> username/password file (call it nodes.txt), grabs these login details,
> Telnet's to a switch, executes a few commands and logs out. Pretty
> simple so far.
>
> I've added two more scripts to encrypt/decrypt the passwords
> (encrypt.c and decrypt.c) from the nodes.txt .. so that if anyone
> tries to read the file, they don't get the password. Decrypt.c only
> accepts requests from main.pl through some hand-shaking. You can't run
> this script on it's own against nodes.txt. So far so good, to recap:
>
> 1. Populate nodes.txt file
> 2. Run the encrypt.c script to encrypt passwords in node.txt
> 3. main.pl calls decrypt.c and stores username/password (which is
> non-encrypted now)
> 4. MY QUESTIONS: Is there a way to ensure that someone can't modify
> the main.pl script to output the password before it gets sent off to a
> switch? Does PERL allow me have hidden variables or some sort?
>
> I give this program out to users to install on their Unix machines
> with root. Anyone with root access can modify the main.pl script .. I
> have no control over that. I just want to see if there's anything I
> can do to hide the password variable in main.pl so they can't simply
> put a print statement on the variable before I call Telnet.
>
> This isn't a banking system model, but so far I can say I have some
> decent work around the encrypt/decrypt portions. There are ways to
> break into this that would require some work/tools, that's a given.
> Now I just need something to make the main.pl a little more hack
> proof.
>
> Thanks in advance!!
------------------------------
Date: 22 Oct 2002 15:12:52 -0700
From: webmaster@smwebdesigns.com (Shelby)
Subject: Re: Hiding password variables in PERL
Message-Id: <ed11fbd8.0210221412.51388f0@posting.google.com>
How about setting any variable used in the decrypt/encrypt to null so
that someone can not alter the main.pl script to list all variables.
Shelby
marcjgpelletier@hotmail.com (Marc Pelletier) wrote in message news:<96f58607.0210220658.1a037ce5@posting.google.com>...
> Alright, so here's the scoop .. wondering if anyone has ever come
> across something like this. Looking for any advice or workarounds as
> well.
>
> I have a main PERL script (call it main.pl) which reads a
> username/password file (call it nodes.txt), grabs these login details,
> Telnet's to a switch, executes a few commands and logs out. Pretty
> simple so far.
>
> I've added two more scripts to encrypt/decrypt the passwords
> (encrypt.c and decrypt.c) from the nodes.txt .. so that if anyone
> tries to read the file, they don't get the password. Decrypt.c only
> accepts requests from main.pl through some hand-shaking. You can't run
> this script on it's own against nodes.txt. So far so good, to recap:
>
> 1. Populate nodes.txt file
> 2. Run the encrypt.c script to encrypt passwords in node.txt
> 3. main.pl calls decrypt.c and stores username/password (which is
> non-encrypted now)
> 4. MY QUESTIONS: Is there a way to ensure that someone can't modify
> the main.pl script to output the password before it gets sent off to a
> switch? Does PERL allow me have hidden variables or some sort?
>
> I give this program out to users to install on their Unix machines
> with root. Anyone with root access can modify the main.pl script .. I
> have no control over that. I just want to see if there's anything I
> can do to hide the password variable in main.pl so they can't simply
> put a print statement on the variable before I call Telnet.
>
> This isn't a banking system model, but so far I can say I have some
> decent work around the encrypt/decrypt portions. There are ways to
> break into this that would require some work/tools, that's a given.
> Now I just need something to make the main.pl a little more hack
> proof.
>
> Thanks in advance!!
------------------------------
Date: Wed, 23 Oct 2002 00:01:54 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How does @EXPORT function in a package?
Message-Id: <slrnarbpqe.kud.mgjv@verbruggen.comdyn.com.au>
On Tue, 22 Oct 2002 15:23:02 +0100,
Richard Gration <richard@zync.co.uk> wrote:
> Hi All,
>
> I was under the impression that any subs in the @EXPORT array in a
> package would automagically appear of the namespace of the script
> "use"ing the package. But I gather from experiments that these subs need
> to be mentioned in @EXPORT_OK too. Is this always the case?
>
> I also find that if I
>
> use Module::Lib qw(:tag);
>
> then if the sub mentioned in @EXPORT is not mentioned in the list for the
> tag, then it's still not imported, even if it _is_ in @EXPORT_OK.
>
> I find all this counter-intuitive. I expected that anything in @EXPORT
> would appear in the namespace of the "use"r, so to speak. Is this ever
> the case?
Maybe it is a bit counter-intuitive, but it is documented. From the
Exporter documentation, section "Specialised Import Lists":
A leading ! indicates that matching names should be
deleted from the list of names to import. If the first
specification is a deletion it is treated as though pre
ceded by :DEFAULT. If you just want to import extra names
in addition to the default set you will still need to
include :DEFAULT explicitly.
The last sentence in this paragraph is what you are looking for.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Curiouser and curiouser, said Alice.
|
------------------------------
Date: Tue, 22 Oct 2002 17:00:14 -0400
From: "Deepa" <tech@REMOVETOMAILall-in-one-business.com>
Subject: NEWBIE foreach problem
Message-Id: <urbf99bqml5e@corp.supernews.com>
Hey, this code is supposed to read a cookie,
separate it into pairs of Item:Quantity and
then break those down into a list of items
stored in a string for sorting.
The code below seems to work fine through the
foreach loop.
#!/usr/bin/perl -w
use CGI qw(:all);
use strict;
# Create a cookie called "testcookie"
my $Cook_sample=cookie( -name => 'testcookie',
-value => '123456:1|234567:3|345678:2',
-expires => '+12h');
print header (-cookie => $Cook_sample);
# Read the Cookie
print header();
my $ItemsInCart = cookie('testcookie');
print "<p> The Variable Items in Cart is $ItemsInCart</p>";
my @EachItem = split('\|', $ItemsInCart);
my $Search_String = "";
my $Long = @EachItem;
print "<p>The number of items in Each Item is $Long</p>";
#When I remove the next lines of code, it executes
#just fine, saying the number of items in $EachItem is 3
#Despite the help, I still can't see what it wrong with
#this code.
foreach $Item (@EachItem) {
@ThisItem = split('\:', $Item);
$Search_String = $Search_String . $ThisItem[0] . " ";
}
print "<p>The search string is $Search_String</p>";
There are probably obvious errors in this, but I am
having trouble seeing them.
Thanks in advance,
Deepa :-)
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.401 / Virus Database: 226 - Release Date: 10/10/02
------------------------------
Date: Tue, 22 Oct 2002 18:54:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: open(STDOUT, ">/dev/null") successful but still get STDOUT output
Message-Id: <3DB5D712.C4C3A083@earthlink.net>
S E H M B wrote:
>
> Hi,
>
> Somewhere in a module, i have the following lines:
>
> ...
> open(STDOUT, '>/dev/null')
> or die("STDOUT open");
> open(STDERR, ">&STDOUT")
> or die("STDERR open");
> print(STDERR "Still gets on the console\n");
> print(STDOUT "Also still gets on the console\n");
> ...
> The last two statements still print out on the terminal.
>
> Now if i put this code in a small test.pl, it works fine. Somehow,
> with all the other code that got loaded / executed before getting
> there, it fails to work.
>
> In particular, on top of that module, i have "use Inline::Files". If i
> put the above code higher than this statement, or uncomment this
> 'use', it works. Yet adding "use Inline::Files" in my test.pl does not
> make it fail (and i need Inline::Files in my module).
>
> I could go on looking for what is causing this by elimination, but
> this could take a while... Can someone give me insight as to what
> could happen that makes the above code behave in they way i describe
> (open()'s successful, yet print()'s still go to the old? fh).
Two possibilities I can think of
First, try replacing the open()s with CORE::open()s.
Second, if that doesn't work, try printing out tied(*STDOUT) and
tied(*STDERR). If STDOUT and STDERR are tied, then that's likely the
problem -- open on a tied handle simply calls $tieobject->OPEN(...),
which can do whatever it wants to do.
> No relevant warnings are displayed, and couldn't find anything related
> to this in Inline::Files docs. Perl 5.6.1 on i686-linux.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 22 Oct 2002 21:43:51 GMT
From: Bryan <bryan@akanta.com>
Subject: perl DBI and prepared statements
Message-Id: <3DB5C696.1010607@akanta.com>
I have read that it is suggested that prepared statements are used with
web based apps that make repetitive sql queries. But how would this
work? As each cgi is executed a new instance of that script is
interpreted and executed, if it does any database stuff, then it
opens/closes a connection with every instance. In this case (if my
logic is correct above), prepared statements are useless unless you are
using mod_perl or some other cached cgi / connection pool setup.
Is this right?
Where does the prepared statement persist, and when will it go away?
Thanks,
Bryan
------------------------------
Date: Tue, 22 Oct 2002 18:43:06 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: perl DBI and prepared statements
Message-Id: <3DB5D47A.40D9BFE1@earthlink.net>
Bryan wrote:
>
> I have read that it is suggested that prepared statements are used
> with web based apps that make repetitive sql queries. But how would
> this work?
Something like:
... global initialization ...
my $sth = $dbh->prepare( q[ SELECT foo FROM bar WHERE baz = ? ] );
... for each query that needs to be made ...
$sth->execute( $query );
while( my $row = $sth->fetchrow_arrayref ) {
...
}
> As each cgi is executed a new instance of that script is
> interpreted and executed, if it does any database stuff, then it
> opens/closes a connection with every instance.
Not all web applications use CGI -- some use mod_perl, some use
mod_fastcgi, some use SpeedyCGI (optionally with mod_speedycgi), some
use php, and so on and so forth. Most of these allow persistant
database connections, which would allow one to do something like what I
outlined above.
Furthermore, it's not uncommon for a cgi program to need to perform
multiple sql queries within a single request.
> In this case (if my logic is correct above), prepared statements are
> useless unless you are using mod_perl or some other cached cgi /
> connection pool setup.
>
> Is this right?
Mostly... As I said, you sometimes do more than one sql query within a
single CGI query.
> Where does the prepared statement persist, and when will it go away?
That depends entirely on the application.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 22 Oct 2002 17:12:59 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: perl DBI and prepared statements
Message-Id: <3DB5DB7B.5FBAE94D@indra.com>
Bryan wrote:
>
> I have read that it is suggested that prepared statements are used with
> web based apps that make repetitive sql queries. But how would this
> work? As each cgi is executed a new instance of that script is
> interpreted and executed, if it does any database stuff, then it
> opens/closes a connection with every instance. In this case (if my
> logic is correct above), prepared statements are useless unless you are
> using mod_perl or some other cached cgi / connection pool setup.
>
> Is this right?
>
> Where does the prepared statement persist, and when will it go away?
>
> Thanks,
> Bryan
I can't answer for all RDBMSs, but with Oracle, each SQL statement is
parsed and held in a portion of the Oracle instance called the 'shared
pool'. When a SQL statement is passed to Oracle, it is checked,
character by character against all statements in the shared pool. If an
exact match is found, the statement is not parsed and the parsed
statement in the shared pool is used. If the statement is not found,
then the statement is parsed (very expensive operation).
What this means for applications is a **HUGE** performance gain. As a
matter of fact, when there are performance problems in an instance I
admin, this is one of the first things I look for.
I would guess this is similar in DB2, Sybase, etc.
--
Ron Reidy
Oracle DBA
------------------------------
Date: Wed, 23 Oct 2002 00:16:48 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Perl Program
Message-Id: <slrnarbqmc.kud.mgjv@verbruggen.comdyn.com.au>
On 22 Oct 2002 09:22:49 -0700,
Aryan <aryan_us1975@yahoo.com> wrote:
> I am populating the two these kind of hashes, it is based upon the what user
> does on the web page. I have to manipulate with these two hashes plzz help
> me..
Manipulate what with these hashes?
> %original_list = (
>
> "name1" => "name1:",
> "name2" => "name2:update",
> "name3" => "name3:update",
> "name4" => "name4:update",
>
> );
>
>
> %changed_list = (
>
> "name1" => "name1:update",
> "name2" => "name2:",
>
> );
Where did these hashes come from, and what is their purpose? The names
suggest something, but it's really not that clear.
> Sub unsubscribe {
>
> }
>
> Sub subscribe{
>
>
> }
Where are the contents of these subroutines? What are they supposed to
do?
> Assumptions:
>
> The changed list would have same number of keys as original or lesser.
Is this an assumption? you create the hashes above yourself, so you
don't need to assume anything. Otherwise, you better check that your
assumption is correct. Anyway, I don't see why it would matter.
> For All the keys which are in originalList but not in chnaged call a
> function called unsubscribe and populate a array called
> unsubscribeArray.
You will need the each() or the keys() functions, together with
exists(). Something like (untested):
for my $key (keys %original_list)
{
unsubscribe($key) unless exists $changed_list{$key};
push @un_array, $key;
}
> Now compare the values for each keys which are there in both of these
> lists::::
Both if which lists? Did you mean the hashes or maybe the array we
just filled? Be clear.
> if in List1 value contains update for perticular key and in list 2 for the
> same key it is null for that key call unsubscribe function and add the
> element into unsubscribed Array.
What are List 1 and List 2? Where did they come from?
> if in List1 value does not contains update for perticular key and in list
> 2 it is update call subscribe function and add the element into subscribed
> Array.
ditto.
What are those two arrays (subscribe and unsubscribe) for? You don't
do anything with them.
Why don't you forget about this algorithm you came up with, and just
tell us what you need to do. maybe we can come up with a much better
and more efficient way to achieve the same goal. I doubt very much
that you need all these multiple passes, and those extra arrays. I
suspect that a single loop over the 'changed' stuff would do what you
are trying to achieve.
This smells a bit like it's part of a homework assignment. If this is
homework, just post the original text of the assignment, and the email
address of your instructor, and we'll do the rest.
Martien
--
|
Martien Verbruggen | That's not a lie, it's a terminological
Trading Post Australia | inexactitude.
|
------------------------------
Date: 22 Oct 2002 11:55:25 -0700
From: liquidphp@yahoo.com (LiquidPHP)
Subject: Running Perl through cron
Message-Id: <8db54e4f.0210221055.4d93b82f@posting.google.com>
I'm encountering a weird problem when running a Perl script from a
cron job. The perl script uses another script to rsync a directory
with four other servers. I am using the fully qualified filename
(/usr/bin/rsynch.sh) to the script in the perl script. When I run the
script from the command line, it works. However, when run from cron,
it returns access denied errors. Everything - the cron job, the
scripts, the directories, etc. - is owned by the same user.
Thanks for your help.
------------------------------
Date: Tue, 22 Oct 2002 23:12:26 GMT
From: "john bennett" <johngnub@worldnet.att.net>
Subject: Re: Running Perl through cron
Message-Id: <uXkt9.18817$Mb3.651893@bgtnsc04-news.ops.worldnet.att.net>
This done not sound like a Perl-ilsh thing, but...
I had some thing like this, I just added in a "whoami" command to the perl
and printed that out to a file, just to gain a point of view from the perl
running under the
cron.
Also don't forget to look at root email, see if cron is yelling about
something, and
the syslog and or the messages files, see if this related to something else
and not the perl/cron.
2 cents JB.
LiquidPHP <liquidphp@yahoo.com> wrote in message
news:8db54e4f.0210221055.4d93b82f@posting.google.com...
> I'm encountering a weird problem when running a Perl script from a
> cron job. The perl script uses another script to rsync a directory
> with four other servers. I am using the fully qualified filename
> (/usr/bin/rsynch.sh) to the script in the perl script. When I run the
> script from the command line, it works. However, when run from cron,
> it returns access denied errors. Everything - the cron job, the
> scripts, the directories, etc. - is owned by the same user.
>
> Thanks for your help.
------------------------------
Date: Tue, 22 Oct 2002 19:20:45 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Running Perl through cron
Message-Id: <3DB5DD4D.BB17A658@earthlink.net>
LiquidPHP wrote:
>
> I'm encountering a weird problem when running a Perl script from a
> cron job. The perl script uses another script to rsync a directory
> with four other servers. I am using the fully qualified filename
> (/usr/bin/rsynch.sh) to the script in the perl script. When I run the
> script from the command line, it works. However, when run from cron,
> it returns access denied errors. Everything - the cron job, the
> scripts, the directories, etc. - is owned by the same user.
>
> Thanks for your help.
And what does this have to do with perl? You would have the same
problem no matter what language you wrote your program in.
The problem is with cron, and unix permissions -- ask in a unix group.
http://groups.google.com/groups?q=group:comp.unix
(Not in that group directly, it's deader than "comp.lang.perl" ... but
one of the subgroups, perhaps c.u.misc or c.u.programmer)
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
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.
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 V10 Issue 4011
***************************************