[16558] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3970 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 9 21:10:32 2000

Date: Wed, 9 Aug 2000 18:10:22 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <965869822-v9-i3970@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 9 Aug 2000     Volume: 9 Number: 3970

Today's topics:
    Re: Perl mods for MySQL (Jon Drukman)
        problems with ^= toddbe@my-deja.com
    Re: reg expressions - protect html <wyzelli@yahoo.com>
        Regexp help, escaping characters <dethtoll@yahoo.com>
    Re: Regexp help, escaping characters (Greg Bacon)
    Re: Set cookie from SSI <flavell@mail.cern.ch>
    Re: Simple regular Expression Question <abe@ztreet.demon.nl>
    Re: Sort of a sort problem. <lr@hpl.hp.com>
    Re: Sort of a sort problem. <stephenk@cc.gatech.edu>
        truncate var spaces fg19537@my-deja.com
    Re: truncate var spaces (Greg Bacon)
        Trying to populate with loop <bunnyman77@hotmail.com>
    Re: Trying to populate with loop (Greg Bacon)
    Re: Trying to populate with loop <sumus@aut.dk>
        variable in sql array not parsed by print <shrivers@nortelnetworks.com>
    Re: variable in sql array not parsed by print (Greg Bacon)
    Re: variable in sql array not parsed (Tim)
    Re: variable in sql array not parsed <abe@ztreet.demon.nl>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 09 Aug 2000 23:47:48 GMT
From: jsd@cluttered.com (Jon Drukman)
Subject: Re: Perl mods for MySQL
Message-Id: <slrn8p3rd4.uec.jsd@cluttered.com>

On Wed, 09 Aug 2000 20:30:54 GMT, <((>< <yamar420@my-deja.com> <> wrote:
>Can someone tell me the correct mod to load for Solaris and MySQL ;perl;
>there seems to be a few ;
>
>DBI-1.13.tar.gz

this is the database "super module".  it uses a DBD::something sub module
to do all the actual dirty work.  the brilliant thing here is that if you
suddenly decide to chuck MySQL and go Oracle, you don't have to rewrite
most of your perl code, because DBI abstracts away the details of the
underlying database as much as possible.

>Msql-Mysql-modules-1.2209.tar.gz

yes, you need this.  this is the sub module that does all the actual
talking to the database.  DBI uses it.

>Data-Dumper-2.101.tar.gz

handy, but not required.

>KAMXbase1.0.tar.gz
>Convert between '.dbf' files and MySQL tables. Perl module written by
>Pratap Pereira

well, if you are migrating dbf files, then yeah, this would be
useful.  if you're starting from scratch, it is not required.

>Data-ShowTable-3.3.tar.gz

optional.

>thanks... I want to run Apache and MySQL , and use a perl and CGI script
>to access my DB..

all you need for that is DBI and the Msql-Mysql-modules.

-jsd-




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

Date: Wed, 09 Aug 2000 22:40:36 GMT
From: toddbe@my-deja.com
Subject: problems with ^=
Message-Id: <8msml3$e9b$1@nnrp1.deja.com>

I'm running this bit of code on an HPUX 10.20 system and a linux system
and get very different resaults.  On the HP $h1 get the correct value on
the linux box $h1 becomes 0.

Is ^= not working under linux?

$h0 += 9804392444;
$h1 += 15433492645;
$h2 += 2607314627;
$h3 += 859226588;
$h4 += 4989140090;

$h1  ^=  $h0;  #$h1 goes to 0 on linux
$h2  ^=  $h0;
$h3  ^=  $h0;
$h4  ^=  $h0;


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 09:06:54 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: reg expressions - protect html
Message-Id: <m1mk5.9$KC1.2186@vic.nntp.telstra.net>

"Keith Calvert Ivey" <kcivey@cpcug.org> wrote in message
news:39935a4c.39641942@news.newsguy.com...
> Stephen Kloder <stephenk@cc.gatech.edu> wrote:
>
> >I've noticed that many here advocate using a(n?) HTML moule to parse
this.
> >But it can be done without one, without getting too ugly:
>
<snip>
>
> By the way, "an HTML module" is correct.  Unless you pronounce
> "HTML" as "hitmull", it starts with a vowel *sound*.  The choice
> of "a" or "an" is determined by pronunciation, not spelling.
> (Well, perhaps I'm being parochial.  There are people in Ireland
> -- and elsewhere? -- who say "haitch-tee-em-ell".)
>

So thats why it sounds so silly when people say "an hotel".

Wyzelli




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

Date: Wed, 09 Aug 2000 23:30:45 GMT
From: Sebastian <dethtoll@yahoo.com>
Subject: Regexp help, escaping characters
Message-Id: <8mspj5$gbf$1@nnrp1.deja.com>

I've got a string like so:

$s = '"this is a text field";1234;"A text; field";4321;"Another text
field"';

Essentially, I want to split it into fields:

@array = split(/;/,$s);

But I don't want to split on a delimiter within quotes, such as in the
third field of my string above. I've played around with lookahead
assertions in my regexps, but to no avail so far.

Can anyone help?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 10 Aug 2000 00:13:23 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Regexp help, escaping characters
Message-Id: <sp3st38hn4t101@corp.supernews.com>

In article <8mspj5$gbf$1@nnrp1.deja.com>,
    Sebastian  <dethtoll@yahoo.com> wrote:

: Essentially, I want to split it into fields:
: 
: @array = split(/;/,$s);
: 
: But I don't want to split on a delimiter within quotes, [...]

Check the FAQ, Section 4:

      How can I split a [character] delimited string except when inside
      [character]? (Comma-separated files)

Greg
-- 
>I need to programmatically reboot a Windows NT 4.0 server using Perl.
Any command in NT has a certain chance to reboot the machine, hasn't it?
    -- Abigail in <7a01hc$lvb$1@client2.news.psi.net>


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

Date: Wed, 9 Aug 2000 23:42:33 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Set cookie from SSI
Message-Id: <Pine.GHP.4.21.0008092339130.27444-100000@hpplus03.cern.ch>

On 9 Aug 2000, bean wrote:

> > tried to use SSI against a program written in COBOL.  Tony already
> > said that, but you didn't want to listen.  Well, do listen.)
> 
> Agreed.

That's decent of you ;-)

> I was being lazy. Sorry. 

Ah, but not in the true Perl sense of "lazy".  Truly lazy people know
where to get a good answer without this kind of fuss.  But you're
getting there, no doubt about that...

> <sigh> My whole process has come crashing down around my ears. 

Well, why not wander off to comp.infosystems.www.authoring.cgi
(check its automoderation rules first though), sketch out a decent
description of what you're actually trying to achieve (i.e NOT just
describe your failed design without saying what it's supposed to be
for), and maybe someone can suggest a workable approach.




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

Date: Thu, 10 Aug 2000 01:32:30 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Simple regular Expression Question
Message-Id: <ipo3pskd2etpp9dqb3nj0sug2sr1n2euq9@4ax.com>

[ please write your response following the (trimmed) quoted text you are
responding to ]
On Wed, 09 Aug 2000 19:57:20 GMT, "Kenny Lim" <kennylim@techie.com>
wrote:

 ...
> #The naming convention for the project-version does not include "." as a
> separator ie ETProj59 since part of the process included is to rename the
> dll files. It will be kinda screwy if it's ETProj5.9.dll, thus this is a
> limitation the project version.

Yeah, it needs a dash and a zero: ETProj-5.09.dll

> Scenario 1 :
> 
> Incrementing the minor version by +1,+2,+3 for ETProj59 will result in 510,
> 511, 512
> rather than  ETProj60, ETProj61, ETProj62. (That's a big jump from version
> 59 to 510,
> 5.9 to version 51.0)
> 
> Scenario 2 :
> 
> Incrementing the minor version by +1,+2, +3 and etc. for ETProj599 will
> result in 5100 rather
> than 600, 601, 602.
> 
> Scenario 3 :
> 
> Incrementing the minor version by +1,+2,+3 and etc. for ETProj999 will
> result in 1099 rather
> than 1000, 1001, 1002.

Now what's so special about '999' (9.99?) that the major version gets to
be incremented, when you want to increment the minor version?

How will you ever decide upon '111'?

[snipped 120 odd lines]
-- 
Good luck,
Abe


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

Date: Wed, 9 Aug 2000 15:43:50 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Sort of a sort problem.
Message-Id: <MPG.13fb7e7d6466d1e098ac56@nntp.hpl.hp.com>

In article <399189C0.24E8BFE1@mortgagestats.com> on Wed, 09 Aug 2000 
11:41:36 -0500, Andras Malatinszky <andras@mortgagestats.com> says...
> Jimmy Lantz wrote:

 ...

> > - Sorts the files in numerical order regardless of prefix into an array.
>
> You could do something like this:
> 
> sub JimmySort
>     {
>     my($alpha,$beta)=($a,$b);
>     $alpha=~s/\D//; #zap all non-digits

That doesn't do what the comment says it does.

      $alpha =~ s/\D+//g;

Or, *much* faster,

      $alpha =~ tr/0-9//cd;

>     $beta=~s/\D//;

Similarly.

>     $alpha<=>$beta;
>     }
> 
> @filelist=qw/dfo131 abe132 abod133 dfo134 abe135 abod136 dfo137/;
> 
> @sorted_filelist=sort JimmySort @filelist;
> 
> Read up on the sort function if this isn't obvious to you.

It isn't the way to do it if performance for a reasonably long list is a 
problem, because the sortkeys (the digits) are extracted far too often 
(once per comparison instead of once per sort).  Use the Schwartz 
Transform posted by Ren Maddux, or the Guttman-Rosler Transform.

See <URL:http://www.hpl.hp.com/personal/Larry_Rosler/sort/> for details.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 09 Aug 2000 20:23:38 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
To: Andras Malatinszky <andras@mortgagestats.com>
Subject: Re: Sort of a sort problem.
Message-Id: <3991F609.F73FA26@cc.gatech.edu>

Andras Malatinszky wrote:

>
> sub JimmySort
>     {
>     my($alpha,$beta)=($a,$b);
>     $alpha=~s/\D//; #zap all non-digits
>     $beta=~s/\D//;
>     $alpha<=>$beta;
>     }
>

This looks effective (I'm sure you meant s/\D//g), but rather inefficient,
since 2 regexes will be evaluated for each comparison.  For larger arrays it
may be better to store the numbers in a separate array, and then sort:
@nums = map{/(\d+)$/} @files;
@sortedfiles = map {$files[$_]} sort {$nums[$a] <=> $nums[$b]} (0..$#nums);

Or, use a one-to-one transformation, which can be easily undone:
@sortedfiles = @files;
s/^(\w+?)(\d+)$/$2$1/ foreach (@sortedfiles);
@sortedfiles = sort @sortedfiles;
s/^(\d+)(\w+)$/$2$1/ foreach (@sortedfiles);

--
Stephen Kloder               |   "I say what it occurs to me to say.
stephenk@cc.gatech.edu       |      More I cannot say."
Phone 404-874-6584           |   -- The Man in the Shack
ICQ #65153895                |            be :- think.




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

Date: Wed, 09 Aug 2000 23:03:30 GMT
From: fg19537@my-deja.com
Subject: truncate var spaces
Message-Id: <8mso00$fcd$1@nnrp1.deja.com>

Thank you Logan Shaw for previous answer.
Related question: I want to use results of one query to perform another.
Is there a better perl programming method of truncating the white spaces
at the end of a variable (while leaving internal spaces alone) than what
I show below? (setting var 3 times)

#!/home/tools/bin/perl -w
use DBI;
$dbh = DBI->connect("DBI:Informix:pro");
$sth = $dbh->prepare(q%select fname, lname
from names%);
$sth->execute();
$ref = $sth->fetchall_arrayref();
for $row (@$ref) {
    $fname = $$row[0];
    $fname =~ s/^\s+//;
    $fname =~ s/\s+$//;
    print "where  fname = '$fname';\n";
}
$dbh->disconnect;
RESULT: where  fname = 'billy bob';
OLD
RESULT: where  fname = 'billy bob   ';


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 09 Aug 2000 23:13:11 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: truncate var spaces
Message-Id: <sp3pc7s5n4t14@corp.supernews.com>

In article <8mso00$fcd$1@nnrp1.deja.com>,
     <fg19537@my-deja.com> wrote:

: Related question: I want to use results of one query to perform another.
: Is there a better perl programming method of truncating the white spaces
: at the end of a variable (while leaving internal spaces alone) than what
: I show below? (setting var 3 times)

Assuming that your notion of "better" is reasonable, no.

Greg
-- 
Chef:    Haven't you ever heard of the Emancipation Proclamation?
General: I don't listen to hip hop.


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

Date: Wed, 09 Aug 2000 17:13:19 -0500
From: Kevin Halverson <bunnyman77@hotmail.com>
Subject: Trying to populate with loop
Message-Id: <3991D77E.EAF61C5B@hotmail.com>

Hello great perl gods!!  I come to you again seeking your infinite
knowledge.

I'm trying to populate this array with the numbers inbetween.  I know
there's a built
in perl function to do this but I want to see it work with a for or
while loop.  I'm using splice to populate it.  This code doesn't work

#!/usr/bin/perl

@ary = (30, 40);
$i = 31;
while ($i < 40)  {
    $a = 0

    splice (@ary, $a + 1, $i);
    $a++;
    }

print "@ary";


Thanks you so much for your help in my perl education.  Kevin.



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

Date: Wed, 09 Aug 2000 23:11:49 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: Trying to populate with loop
Message-Id: <sp3p9lfdn4t44@corp.supernews.com>

In article <3991D77E.EAF61C5B@hotmail.com>,
    Kevin Halverson  <bunnyman77@hotmail.com> wrote:

: I'm trying to populate this array with the numbers inbetween.  I know
: there's a built-in perl function to do this but I want to see it work
: with a for or while loop.

Any particular reason?

:                            I'm using splice to populate it.  This code
: doesn't work
: 
: #!/usr/bin/perl
: 
: @ary = (30, 40);
: $i = 31;
: while ($i < 40)  {
:     $a = 0
: 
:     splice (@ary, $a + 1, $i);
:     $a++;
: }
: 
: print "@ary";

You didn't increment $i.

The easy way is, of course,

    @ary = ($ary[0] .. $ary[1]);

You could do

    my $stop = pop @ary;

    if ($stop > $ary[0]) {
        for (my $i = $ary[0]+1; $i < $stop; $i++) {
            push @ary, $i;
        }
    }
    elsif ($stop < $ary[0]) {
        for (my $i = $ary[0]-1; $i > $stop; $i--) {
            push @ary, $i;
        }
    }

    push @ary, $stop;

If you're determined to use splice(), do

    my $stop = pop @ary;

    if ($stop > $ary[0]) {
        for (my $i = $ary[0]+1; $i < $stop; $i++) {
            splice @ary, @ary, 0 => $i;
        }
    }
    elsif ($stop < $ary[0]) {
        for (my $i = $ary[0]-1; $i > $stop; $i--) {
            splice @ary, @ary, 0 => $i;
        }
    }

    push @ary, $stop;

The push/splice equivalence is documented in the splice documentation
in the perlfunc manpage.

Greg
-- 
Nothing defines humans better than their willingness to do irrational things
in the pursuit of phenominally unlikely payoffs. 
    -- Scott Adams


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

Date: 10 Aug 2000 01:31:54 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Trying to populate with loop
Message-Id: <aeem6mfp.fsf@macforce.sumus.dk>

Kevin Halverson <bunnyman77@hotmail.com> writes:

> I'm trying to populate this array with the numbers inbetween.
[...]
> @ary = (30, 40);
> $i = 31;
> while ($i < 40)  {
>     $a = 0
> 
>     splice (@ary, $a + 1, $i);
>     $a++;
>     }
> 
> print "@ary";

What you really need is to check perldoc -f splice.

If you insist on while and a counter:

use strict;

my @ary = ( 30, 40 );
my $i = 31;
while ( $i < 40 )  {
    splice @ary, -1, 0, $i;
    $i++;
}

print "@ary\n";

- You might also try a for loop (this is the one case for which the C-style
for loop is really cool):

use strict;

my @ary = ( 30, 40 );
for ( my $i = 31; $i < 40; $i++ )  { splice @ary, -1, 0, $i }

print "@ary\n";

- I think i like this better though:

use strict;

my @ary = ( 30, 40 );
splice @ary, 1, 0, 31..39;

print "@ary\n";


-- 
Jakob Schmidt
http://aut.dk/orqwood
etc.


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

Date: Wed, 09 Aug 2000 22:42:56 GMT
From: Steve Shriver <shrivers@nortelnetworks.com>
Subject: variable in sql array not parsed by print
Message-Id: <8msmpg$eh2$1@nnrp1.deja.com>

My goal is to get a SQL statement to include a variable (as a string)
that PERL interprets at runtime.

Here's the SQL that is being processed by a subroutine against an Oracle
database, using DBI.pm:
   SELECT coeo,
      '$JIT_OrderStatus['||order_status||']',
      TO_CHAR(doc_ordered, 'MM/DD/YYYY'),
      waybill,
      carrier
   FROM  feeds
   WHERE  coeo like '$coeo'
   AND order_status is not null
   ORDER BY coeo DESC

which is processed like this:
  while(@row = $sth->fetchrow_array) { ...
    for $col (0..$number_of_cols) {
         $buff .= "<TD ALIGN=LEFT valign=top>$row[$col]</TD>\n";
        }
     ...
   }
   print $buff;

Now the trick is in the second element in the @row array; it contains
the string "$JIT_OrderStatus[3]" which is another array elsewhere in the
code. Thus, the $buff looks like this:
 <TD ALIGN=LEFT valign=top>$JIT_OrderStatus[3]</TD>

** So how do I get the $buff to execute the embedded variables? **

Thanks for the help!
Steve


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 09 Aug 2000 23:00:13 GMT
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: variable in sql array not parsed by print
Message-Id: <sp3ojte2n4t19@corp.supernews.com>

In article <8msmpg$eh2$1@nnrp1.deja.com>,
    Steve Shriver  <shrivers@nortelnetworks.com> wrote:

: Now the trick is in the second element in the @row array; it contains
: the string "$JIT_OrderStatus[3]" which is another array elsewhere in the
: code. Thus, the $buff looks like this:
:  <TD ALIGN=LEFT valign=top>$JIT_OrderStatus[3]</TD>
: 
: ** So how do I get the $buff to execute the embedded variables? **

Your frequently asked question is answered in Section 4 of the Perl FAQ.

Greg
-- 
Only two things are infinite, the universe and human stupidity, and I'm not
sure about the former. 
    -- Albert Einstein


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

Date: Wed, 09 Aug 2000 22:09:35 GMT
From: SPAM+indigo@dimensional.com (Tim)
Subject: Re: variable in sql array not parsed
Message-Id: <8F8BA92F0indigodimcom@166.93.207.145>

steve_shriver@my-deja.com wrote in <8msitm$bl9$1@nnrp1.deja.com>:

>My goal is to get a SQL statement to include a variable (as a string)
>that PERL interprets at runtime.
>
>Here's the SQL that is being processed by a subroutine against an Oracle
>database, using DBI.pm:  SELECT coeo,
>'$JIT_OrderStatus['||order_status||']', TO_CHAR(doc_ordered,
>'MM/DD/YYYY'), waybill, carrier FROM feeds  WHERE     coeo like 'H2S65%'
> AND order_status is not null  ORDER BY coeo DESC 

You probably need to set up a bind variable:

# Warning: Untested code fragment

use DBI;

my $dbh = DBI->connect(...db connect stuff...);

my $sql = 'select * from table where column = :1';

my $sth = $dbh->prepare($sql);

my $value = some_complicated_function();

$sth->bind_param(1, $value);

while (my @row = $sth->fetchrow_array())
{
    # Do stuff
}

perldoc DBI for more info.

-T


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

Date: Thu, 10 Aug 2000 02:34:05 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: variable in sql array not parsed
Message-Id: <8et3ps8dig59uorpl7vhu3l9p14s5frn5u@4ax.com>

On Wed, 09 Aug 2000 21:36:54 GMT, steve_shriver@my-deja.com wrote:

> My goal is to get a SQL statement to include a variable (as a string) that
> PERL interprets at runtime.
> 
> Here's the SQL that is being processed by a subroutine against an Oracle
> database, using DBI.pm:  SELECT coeo, '$JIT_OrderStatus['||order_status||']',
> TO_CHAR(doc_ordered, 'MM/DD/YYYY'), waybill, carrier FROM feeds  WHERE	coeo
> like 'H2S65%'  AND order_status is not null  ORDER BY coeo DESC

Please show _real_ code next time, now we have to guess, it's waste of
time really.

Is '$JIT_OrderStatus' a scalar? If so use curlies around the name:
'${JIT_OrderStatus}['

If you are on the other hand addressing an element of @JIT_OrderStatus,
you have a sytax-error.

-- 
Good luck,
Abe


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3970
**************************************


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