[23574] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5781 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 11 14:06:18 2003

Date: Tue, 11 Nov 2003 11:05:15 -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           Tue, 11 Nov 2003     Volume: 10 Number: 5781

Today's topics:
    Re: Bug in 5.8.0? . op is very slow <daniel.rawson.take!this!out!@asml.nl>
    Re: Calling a sub in main script from module <usenet@morrow.me.uk>
    Re: Calling a sub in main script from module <usenet@morrow.me.uk>
    Re: Calling a sub in main script from module (fatted)
    Re: Calling a sub in main script from module (Tad McClellan)
    Re: count of 1s in a binary number (Anno Siegel)
        Creating and submitting POST form in Perl (J.P.)
    Re: globals and while <uri@stemsystems.com>
    Re: How to simulate keyboard.../dev/tty0? <nobull@mail.com>
    Re: installing perl <kingsman22004@yahoo.com>
    Re: JVM in perl (Tad McClellan)
    Re: JVM in perl <chris.uppal@metagnostic.REMOVE-THIS.org>
    Re: LWP::UserAgent and SSL is it impossible? (Peter Scott)
    Re: my command (sorry newbe question) (Tad McClellan)
        perl CGI file upload memory leak <lionel.valero@polymtl.ca>
    Re: Perl module for analyzing log files? <massi@NOSPAMmassimilianosini.it>
    Re: Perl Newbie <uri@stemsystems.com>
    Re: print statement spanning multiple lines <bmb@ginger.libs.uga.edu>
    Re: Problems with Sendmail <bmb@ginger.libs.uga.edu>
        redirecting webpage (finding out the name of the server <_nospam_stigerikson@yahoo.se>
        small dbi help (debraj)
    Re: small dbi help <ThomasKratz@REMOVEwebCAPS.de>
    Re: small dbi help <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 11 Nov 2003 10:29:08 -0500
From: Dan Rawson <daniel.rawson.take!this!out!@asml.nl>
Subject: Re: Bug in 5.8.0? . op is very slow
Message-Id: <boqv8h$1grg9p$1@ID-122008.news.uni-berlin.de>

Matthias Weckman wrote:
> Hi all,
> 
> I hope you may be able to shed some light on this.
> I'm using ActiveState Perl 5.8.0 (build 806) on Windows 2000, and 
> noticed that slurping a file was very slow compared to the old 5.6.1.
> 
> I narrowed it down to the . operator taking a lot of time, see the 
> script below. 

> Is this an issue with ActiveState's build only? Or is it a 5.8.0 issue 
> in general? Do you know if it has been fixed in 5.8.1?
> Is there a way to improve this?
> 

This appears to be only in the Win32 ActiveState builds; build 806 / 635 on Solaris don't exhibit the same behavior. Our source builds on Solaris also don't display the same behavior. 

Filed as bug 28167 at ActiveState (cf also bug 26762).
http://bugs.activestate.com/show_bug.cgi?id=28167

Dan



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

Date: Tue, 11 Nov 2003 14:06:09 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Calling a sub in main script from module
Message-Id: <boqqch$f10$1@wisteria.csv.warwick.ac.uk>


Matthias Weckman <matthias_weckman@hotmail.com> wrote:
> While you're asking... A correct way of testing if a file is readable is 
> using the -r or -R file test. (See the first entry in the Alphabetical 
> section of perlfunc).
> You don't have to open the file to see if you can read from it:

However, it is more better to. If you test with -r then there is a
race condition between when you make the test and when you
subsequently open the file: the permissions could have changed.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.  |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|  ben@morrow.me.uk


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

Date: Tue, 11 Nov 2003 14:14:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Calling a sub in main script from module
Message-Id: <boqqs6$f10$2@wisteria.csv.warwick.ac.uk>


Ben Morrow <usenet@morrow.me.uk> wrote:
> However, it is more better to.

I do know how to speak English, honest... :(

Ben

-- 
don't get my sympathy hanging out the 15th floor. you've changed the locks 3
times, he still comes reeling though the door, and soon he'll get to you, teach
you how to get to purest hell. you do it to yourself and that's what really
hurts is you do it to yourself just you, you and noone else *  ben@morrow.me.uk


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

Date: 11 Nov 2003 08:06:55 -0800
From: obeseted@yahoo.com (fatted)
Subject: Re: Calling a sub in main script from module
Message-Id: <9edc36a2.0311110806.107455a2@posting.google.com>

Matthias Weckman <matthias_weckman@hotmail.com> wrote in message news:<3fb0cbd3$0$50813$c4fe714e@dreader10.xs4all.nl>...
> fatted wrote:

<snip>

> > Whats the correct way to do this?
> 
> main::write_log(...).

I have no idea where that dollar came from. I was beating my head for
hours over that. I am now attempting to engage my brain :)

> While you're asking... A correct way of testing if a file is readable is 
> using the -r or -R file test. 

I was just giving a simple example to show the problem, not ideal code
(or even close :)


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

Date: Tue, 11 Nov 2003 11:32:56 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Calling a sub in main script from module
Message-Id: <slrnbr27a8.erp.tadmc@magna.augustmail.com>

Ben Morrow <usenet@morrow.me.uk> wrote:
> Ben Morrow <usenet@morrow.me.uk> wrote:
>> However, it is more better to.
> 
> I do know how to speak English, honest... :(


English to speak you do know how.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 11 Nov 2003 18:45:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: count of 1s in a binary number
Message-Id: <boraod$q8t$2@mamenchi.zrz.TU-Berlin.DE>

Steffen Beyer <steffen.beyer@de.bosch.com> wrote in comp.lang.perl.misc:
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> wrote in message
> news:boj8vt$iui$1@mamenchi.zrz.TU-Berlin.DE...
> 
> > Putting it together:
> > 
> >     sub size2 {
> >         my $n = shift;
> >         my $size = $n ? 1 : 0;
> >         $size++ while $n ^= (($n - 1) ^ $n) & $n;
> >         $size;
> >     }
> 
> Note that the "XOR" operation is superfluous.
> 
> This also works (C code):
> 
>         int c = 0xDEADBEEF; /* or whatever */
>         int count = 0;
>         while (c)
>         {
>             c &= c - 1;

Oh, right.  It's that simple.

>             count++;
>         }
> 
> Should work similarly in Perl.
> 
> BTW, that's exactly what the module "Bit::Vector" uses internally.

Have you considered a lookup-table?  A byte lookup does eight bits in one
addition (and the table lookup).  If half the bits are set on average,
a byte takes four counting steps in your loop.

Of course, a table is a boring piece of furniture, comparatively...

A little elaboration on the trick gives the number of the LSB:

sub low_bit {
    my $x = shift;
    int( 0.5 + log( $x & ~( $x - 1))/log( 2));
}

That's of little use in assembler or C, but in Perl it's fine.

Anno



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

Date: 11 Nov 2003 10:48:25 -0800
From: john.p.zurilgen@saic.com (J.P.)
Subject: Creating and submitting POST form in Perl
Message-Id: <9d142b04.0311111048.71f89b83@posting.google.com>

To anyone who might be able to help here,

I am not necessarily new to Perl, but I have a question regarding
creating and submitting a POST form in Perl.  I know how to use the
CGI.pm module to create dynamic pages, but I don't necessarily want to
display a page here.

I am creating a process where my script automagically runs, creates a
POST request (automagically filling in all the required data) and
submits itself to a particular web page for processing.  I intend to
capture the response from the web page and parse out all data that I
need.

I've been seeking a way to create a POST form in Perl and handling the
auto-submission.  But, how can I do this?  I don't need to display my
form that Perl will create....I just need to create the request and
fire it off.

If ANYONE out there can help me, I would greatly appreciate it.  I've
been going in circles now for 3 days, trying to scour the web and
books for answers.  Nothing...

Thank you VERY much in advance for any help!

J.P. Zurilgen
Sr. Solutions Developer, SAIC


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

Date: Tue, 11 Nov 2003 16:25:41 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: globals and while
Message-Id: <x7llqmyire.fsf@mail.sysarch.com>

>>>>> "AQ" == Ala Qumsieh <qumsieh@cim.mcgill.ca> writes:

  >> how are those the same? the OP's code was a single statement, yours is a
  >> while with a block. in the former, my $y means $y is not visible until
  >> the next statement. in your code $y is visible to the code in the block.

  AQ> I never said they were the same, just that I thought they were
  AQ> semantically (sic) identical. I guess I'm wrong, but I don't
  AQ> really understand why. You say that in the OP's code, the $y is
  AQ> not visible until the next statement, but that doesn't seem
  AQ> intuitive to me since the "body" of the while loop (i.e the print
  AQ> statement) will not execute until after the condition (setting my
  AQ> $y = $x--) has been tested, at which point $y has been defined as
  AQ> a lexical variable. And since it's defined in the condition part
  AQ> of the while loop, then it ought to be available in the body, just
  AQ> like my longer version of the code. To me (and I have never
  AQ> designed a language, so please excuse my ignorance), both versions
  AQ> of the code ought to behave the same way (the OP's version has an
  AQ> "invisible block" if you will). But, I get the feeling that this
  AQ> might break something.

there is NO block in the single statement line. so my $y is not declared
yet and can't be refered to in the same statement. there is NO implicit
block as it is a single statement with a modifier.

in the blcok form, the my $y is visible to the BLOCK as it is not in the
same statement line as the declaration.

  AQ> Btw, is this related to the fact that in statements of the form "EXPR
  AQ> foreach EXPR" you can only use $_ as your loop variable?

larry never created a syntax that would support a named lexical
there. it could be for a similar reason.

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: 11 Nov 2003 17:59:41 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: How to simulate keyboard.../dev/tty0?
Message-Id: <u9ekweokfm.fsf@wcl-l.bham.ac.uk>

Keeper <keeper@iosys.no-ip.org> writes:

> Newsgroups: alt.perl,comp.lang.perl,comp.lang.perl.misc,comp.lang.perl.modules

comp.lang.perl does not exist (see FAQ) - please don't start any
threads there.  Nobody will see your message there except the clueless
and those of us who periodically visit from comp.lang.perl.misc to
rescue the clueless.

Please don't cross-post alt.perl and comp.lang.perl.* - the people who
hang out in alt.perl tend to do so because they found comp.lang.perl.*
"unfriendly". (Actully, they usually found it to be intollerant of
selfishness).  Duping these people into posting to comp.lang.perl
won't make either them or us happy.

By definition comp.lang.perl.misc is for stuff that doesn't have a
more specific home in comp.lang.perl.*.  As such it is very rarely
appropriate to cross-post comp.lang.perl.misc and another
comp.lang.perl.* group.

> my $st = 'K'
> my $ri = 'L'
> my $ng = 'J'
> open(TTY, ">/dev/tty0");
> ioctl(TTY, &TIOCSTI, $st);
> ioctl(TTY, &TIOCSTI, $ri);
> ioctl(TTY, &TIOCSTI, $ng);
>
> I'm using redhat 9, kde.
> Everything is ok in the linux console (on tty1 chars are sending
> properly - KLJ...), but in kde i see strange things (and not only for
> those characters):
> ^[[D- 	on ttyp1
> - 	on mozilla window
> My question is why chars are not properly sending by ioctl call, is
> there any additional settings to do (setting termios, keyboard
> driver?)??

Your question has nothing whatever to do with Perl.  Whatever the
answer it would be exactly the same whatever language you used to
issue those ioctl()s.

IIRC the X server puts the tty device into a mode where keys generate
hardware specific scan-codes not ASCII(-like) codes.  If you wish to
put keys into the tty keyboard stream that goes to the X server then
you'd need to use scan-codes.  There are also mechanisms to inject
events into X but I don't know anything about them.

(Like I say I'm not an expert on this - but then if you are looking
for experts on this you are in the wrong place).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Wed, 12 Nov 2003 05:41:20 +1100
From: King <kingsman22004@yahoo.com>
Subject: Re: installing perl
Message-Id: <3FB12D50.5000908@yahoo.com>

isn't ture that with debian, I better install perl in a different 
directory so it does not interfere with debian stock perl? and what does 
that mean? when make install puts its files in whatever place it likes 
and that include locations other than -r /home/username/perl-5.8.1.
I don't understand the objective here inorder not to interfere with 
debian stock perl. ok back to my problem solving steps.

# cd /home/username
# tar -zxvf stable.tar.gz
# cd perl-5.8.1
# sh Configure -de
# make
# make test
# make install


# ln -sf perl5.6.1 /usr/bin/perl
# ln -sf perl5.8.1 /usr/local/bin/perl
# /usr/bin/perl -v

This is perl, v5.6.1 built for i686-linux
<snip>

# /usr/local/bin/perl -v

This is perl, v5.8.1 built for i686-linux
<snip>


now what... when I run a file.pl, do I need to start the file with 
#!/usr/local/bin/perl instead of #!/usr/bin/perl?

how about installing tha CPAN to keep up with cpan modules? also I need 
to install Data::Dumpber, I never did this before, do I follow 
instruction off the net from a reliable source like perlmonks, or I need 
to do thing differently. I will try not to do somthing I don't full 
understand next time.

thanks



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

Date: Tue, 11 Nov 2003 09:06:08 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: JVM in perl
Message-Id: <slrnbr1un0.ee2.tadmc@magna.augustmail.com>

Mc Kiernan, Daniel Kian <Mc-Kiernan@bogus-subdomain.worldnet.att.net> wrote:

> I'm planning an implementation of the JVM in perl.


Why are you planning an implementation of the JVM in perl? 

(I think you meant "Perl" rather than "perl" ? )

What do you hope to gain by adding another level of virtual machine
(ie. adding perl's VM (byte codes) in addition to Java's byte codes).

It will be boatloads slower than one written in a compliled language,
so what advantage do you hope to gain by your efforts?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 11 Nov 2003 16:53:27 -0000
From: "Chris Uppal" <chris.uppal@metagnostic.REMOVE-THIS.org>
Subject: Re: JVM in perl
Message-Id: <3fb113f0$0$110$65c69314@mercury.nildram.net>

Tad McClellan wrote:

> What do you hope to gain by adding another level of virtual machine
> (ie. adding perl's VM (byte codes) in addition to Java's byte codes).

Aw, c'mon man, where's your sense of fun ?

What *else* would you use for running jython ?

Anyway, for someone who likes Perl -- a set of which I am not a member -- and
who feels comfortable writing middle-sized applications in that language, and
who wanted to learn about the JVM by creating a *very simple* implementation,
Perl might not be a bad choice of language.

Writing a fast, JITed implementation bootstrapped from Perl, now *that* would a
challenge...

    -- chris




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

Date: Tue, 11 Nov 2003 15:40:20 GMT
From: peter@PSDT.com (Peter Scott)
Subject: Re: LWP::UserAgent and SSL is it impossible?
Message-Id: <Ep7sb.368705$6C4.124352@pd7tw1no>

In article <kpd1rvgplji6vsl9h07ju3h81l06lknmgt@4ax.com>,
 Helgi Briem <HelgiBriem_1@hotmail.com> writes:
>On Mon, 10 Nov 2003 17:49:02 -0700, Paul Lemmons
><paul@not2bspammed.com> wrote:
>
>>I want to script a login to a secure web site in perl. The web site is 
>>using session cookies and SSL. It is not using basic authentication. No 
>>matter what I try I always get "Authentication failed!" returned from 
>>the server.
>
>Install the Crypt::SSLeay module, then add the line 
>
>use Crypt::SSLeay;

You don't need to add that line to make HTTP over SSL work; 
installing the module makes LWP work with the https schema
transparently.  If the OP's problem was that he didn't have
Crypt::SSLeay installled, LWP would have told him so on
the request().

Perhaps there is a character in the password that should
undergo encoding.  The poster would be better off sending
the content using, say, HTTP::Request::Common::POST
which relieves the user of having to worry about encoding.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/


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

Date: Tue, 11 Nov 2003 08:59:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: my command (sorry newbe question)
Message-Id: <slrnbr1ub4.ee2.tadmc@magna.augustmail.com>

Torch <rvw_torch@hotmail.com> wrote:

> I noticed a lot of "my"
> commands before declaring a variable. 


my() is not a command.

It is not "before" declaring a variable, my() _is_ the
declaring of the variable.


> I was under the impression that
> the "my" command was only used to declare a variable locally (like for
> instance in a subroutine). 


It is used to control scope, whether the scope extends for a block
or for an entire file.


> I noticed from a code I got that in some
> cases "my" was used and in other cases not. Can somebody help me with
> understanding when to use "my" and when not to use "my"


   You should always prefer lexical (my) variables over
   dynamic (our) variables, except when you can't.


See:

   perldoc -q my

       What's the difference between dynamic and lexical (static)
       scoping?  Between local() and my()?

and:

   perldoc strict


See also:

   "Coping with Scoping":

      http://perl.plover.com/FAQs/Namespaces.html


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Tue, 11 Nov 2003 17:54:32 GMT
From: Lionel Valero <lionel.valero@polymtl.ca>
Subject: perl CGI file upload memory leak
Message-Id: <sn9sb.28674$Ng3.13352@charlie.risq.qc.ca>

Hello,

perl v5.8.0
CGI.pm-3.00
http-2.0.48

Everytime i upload a file via my perl script, the amount of bytes transfered 
(size of the uploaded file) are not released from memory.

I closed the file handle of the new created file.

Any idea ?

Regards.



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

Date: Tue, 11 Nov 2003 17:53:38 GMT
From: Massi <massi@NOSPAMmassimilianosini.it>
Subject: Re: Perl module for analyzing log files?
Message-Id: <Xns9430C00D5AB9Fmassi70Massi@195.31.190.131>

Kenneth Porter <ken.blacklist@sewingwitch.com> wrote in 
news:Xns942CCFBD5CF0Cshivawellcom@64.164.98.51:

> Massi <massi@NOSPAMmassimilianosini.it> wrote in 
> news:Xns942C86A868661massi70Massi@195.31.190.132:
> 
>> Try using Date::Parse
> 
> Thanks. How does that compare to Date::Manip or Time::ParseDate?
> 

Sorry ...
I never used those modules...

M.


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

Date: Tue, 11 Nov 2003 16:28:12 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Perl Newbie
Message-Id: <x7islqyin7.fsf@mail.sysarch.com>

>>>>> "DKW" == David K Wall <usenet@dwall.fastmail.fm> writes:

  DKW> Uri Guttman <uri@stemsystems.com> wrote:

  AK> http://www.perl.org/books.html
  >> 
  >> and even better is the perl books site:
  >> 
  >> books.perl.org

  DKW> I didn't know that site existed.  It seems like duplication of
  DKW> effort to have a list on learn.perl.org and another (larger) one
  DKW> on books.perl.org.  Are the maintainers of the two sites
  DKW> coordinating their efforts?  If not, I think they should be....

the former is a general page with links to books lists (and to the
books.perl.org page). the latter is a comprehensive site listing all (or
most) known perl books. it has a search engine, ratings, reviews,
categories, skill levels, etc. it is not just a list of books. it is
intended to be the main books page for the perl community. you can all
login and add ratings and reviews and such.

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: Tue, 11 Nov 2003 09:50:00 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: print statement spanning multiple lines
Message-Id: <Pine.A41.4.58.0311110948120.18784@ginger.libs.uga.edu>

On Tue, 11 Nov 2003, Gregory Toomey wrote:

> It was a dark and stormy night, and Voitec managed to scribble:
>
> > Hi,
> >
> > St00pid question time:
> > How can I make a print statement span several lines without affecting the
> > final formatting?
> >
> The most obvious way us to use "\n" for newline
>
> print "line a\nline b\n\nline c";
>
> Try 'man printf' for a list of other options (C and Perl share some libraries).
>
> gtoomey
>

Are you sure you didn't misread that questions as:

How can I make the final formatting span several lines without affecting
the print statement?

:-)

Regards,

Brad


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

Date: Tue, 11 Nov 2003 09:52:20 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: Problems with Sendmail
Message-Id: <Pine.A41.4.58.0311110951200.18784@ginger.libs.uga.edu>

On Tue, 11 Nov 2003, Gunnar Hjalmarsson wrote:

> Phantom_guitarist wrote:
> > If any one knows of any issues that I am maybe overlooking your
> > help would be very much appreciated.
>
>      open(MAIL,'|$mailprog -t')|| &error("Cant locate mail program");
> -------------------------^^^

Also:

     open(MAIL,"|$mailprog -t")|| &error("Cant locate mail program");

Regards,

Brad


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

Date: Tue, 11 Nov 2003 19:22:39 +0100
From: stig <_nospam_stigerikson@yahoo.se>
Subject: redirecting webpage (finding out the name of the server)
Message-Id: <bor9ia$7ju$1@oden.abc.se>

hi

in a web-application we use a form where people enter some information.
when they save the information the page should save and then redirect to 
another page. as far as i know to redirect the has to use non-relative 
path to redirect to.
and here comes the problem, we use two servers and round robin, so i 
would like the script to redirect to the currently used server.

is it at all possible to make relative redirections (not giving entire 
server path ie: http://www1.some.com/cgi-bin/next_page.cgi)?

or, how do i find out the name or IP of the server that is used 
currently (www1.some.com or www2.some.com) so that i can build a 
non-relative path myself?

thanks in advance
stig


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

Date: 11 Nov 2003 09:04:35 -0800
From: debhatta@hotmail.com (debraj)
Subject: small dbi help
Message-Id: <f9f243e.0311110904.643b9864@posting.google.com>

Hi,

Just wanted a small help. I have a perl script (OS:Linux) in which I
am repeatedly evoking sqlplus, for connecting to the database(Oracle)
because the select statement changes often(about 500 times) and its
taking a lot of time. Now, I know this much that DBI helps in
connecting to the database and can do SQL queries but how much will it
improve the performance? The query is very simple only that the select
clause changes.

OR is there any better way to do it? 

Example: select * from emp where emp_no=****;
The above is the query and in a loop the emp_no changes about 500
times.

Thanx in advance,

Debhatta


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

Date: Tue, 11 Nov 2003 18:25:02 +0100
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: small dbi help
Message-Id: <3fb11c2a.0@juno.wiesbaden.netsurf.de>

debraj wrote:

> Hi,
> 
> Just wanted a small help. I have a perl script (OS:Linux) in which I
> am repeatedly evoking sqlplus, for connecting to the database(Oracle)
> because the select statement changes often(about 500 times) and its
> taking a lot of time. Now, I know this much that DBI helps in
> connecting to the database and can do SQL queries but how much will it
> improve the performance? The query is very simple only that the select
> clause changes.
> 
> OR is there any better way to do it? 
> 
> Example: select * from emp where emp_no=****;
> The above is the query and in a loop the emp_no changes about 500
> times.

Using DBI will help you in at least 2 ways. First you'll save process 
creation time for shelling out to sqlplus 500 times.
Second you will be able to prepare the select statement with a 
placeholder, so that you can execute the statement later many times 
with different values for the placeholder.
The gain in speed should be quite noticable.

Like this (only a quick outline)

use DBI;
my $db = DBI->new(<insert connection parameters here>);
my $st = $db->prepare("select * from emp where emp_no=?");

for my $emp (1..500) {
    $st->execute($emp);
    $st->dump_results();
}

Thomas



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

Date: 11 Nov 2003 17:39:13 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: small dbi help
Message-Id: <u9islqoldq.fsf@wcl-l.bham.ac.uk>

debhatta@hotmail.com (debraj) writes:

> Just wanted a small help. I have a perl script (OS:Linux) in which I
> am repeatedly evoking sqlplus, for connecting to the database(Oracle)
> because the select statement changes often(about 500 times) and its
> taking a lot of time. Now, I know this much that DBI helps in
> connecting to the database and can do SQL queries but how much will it
> improve the performance?

It will probably be a lot (several orders of magnitude) more efficient
than creating a process, creating a connection, then tearing it all
down again for every record you retrive.

> The query is very simple only that the select
> clause changes.
> 
> OR is there any better way to do it? 
> 
> Example: select * from emp where emp_no=****;
> The above is the query and in a loop the emp_no changes about 500
> times.

In that case there is no need for the SELECT to change, only the
parameter.

my $sth = $db->prepare('select * from emp where emp_no=?');

for my $emp_no ( @emp_nos ) {
   $sth->execute($emp_no);
   my $emp_record = $sth->selectrow_hashref;
   $sth->finish; # Redundant if emp.emp_no is PK
   # Do stuff with $emp_record
}

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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


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