[18667] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 835 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 4 14:05:43 2001

Date: Fri, 4 May 2001 11:05:10 -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: <988999510-v10-i835@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 4 May 2001     Volume: 10 Number: 835

Today's topics:
    Re: Active perl problem nobull@mail.com
    Re: CGI with conditional GET nobull@mail.com
    Re: Compare 2 arrays <vmurphy@Cisco.Com>
    Re: Compare 2 arrays <dwb1@home.com>
    Re: Compare 2 arrays (Logan Shaw)
    Re: Compare 2 arrays <juex@deja.com>
    Re: Compare 2 arrays (Tad McClellan)
    Re: connect timeouts nobull@mail.com
    Re: Downloading images with HTTP/LWP libraries <godzilla@stomp.stomp.tokyo>
    Re: Downloading images with HTTP/LWP libraries <godzilla@stomp.stomp.tokyo>
        File transfers <h.k.k.eriksen@astro.uio.no>
        GDBM::reorganize? <cfour@americasm01.nt.com>
    Re: GDBM::reorganize? <cfour@americasm01.nt.com>
        leftover Close Wait sockets (Spork Boy)
        newbie questions <mauricio.leiva@ubinet.cl>
    Re: newbie questions nobull@mail.com
        Perl and MySQL problem <kingfu@blueyonder.co.uk>
    Re: Perl and MySQL problem (John Joseph Trammell)
    Re: Perl and MySQL problem <vmurphy@Cisco.Com>
    Re: Perl and MySQL problem (Tad McClellan)
    Re: Perl and MySQL problem (John Joseph Trammell)
        Perl and Mysql <kingfu@blueyonder.co.uk>
        Poetry::Aum version 0 released <Home@LeeGoddard.com>
    Re: Printing HTTP headers/body in perl <mail@NOSPAMericmarques.net>
    Re: Printing HTTP headers/body in perl <godzilla@stomp.stomp.tokyo>
    Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
    Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
    Re: Problem with the subroutine (closure?) for the "sor nobull@mail.com
        Problems with Crypt::Blowfish/Crypt::CBC <rlf@proimages.net>
    Re: Rename subdirectories and files nobull@mail.com
    Re: Rename subdirectories and files (Tad McClellan)
        use Apache::Htpasswd <Mike.Song@usa.net>
        very big array <T_boss75@curanet.com>
    Re: very big array nobull@mail.com
        warnings from MIME-Lite <msolomon@3s-technology.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 04 May 2001 17:40:48 +0100
From: nobull@mail.com
Subject: Re: Active perl problem
Message-Id: <u9d79prrsf.fsf@wcl-l.bham.ac.uk>

"Si" <DieSpamDieLisaandsi@btinternet.com> writes:

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

comp.lang.perl does not exist - ask your newserver provider to fix
their server.

> I am currently in the process of learning Perl,

>  #!/usr/local/bin/perl
>  require "cgi-lib.pl";
>  &ReadParse(*form_data);

If you are currently in the process of leaning Perl there's not much
point leaning how to program for Perl4.  Sure you Perl4 scripts will
run under Perl5 but everyone you show them to will look at them in
stunned disbelief and revulsion.

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


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

Date: 04 May 2001 18:24:52 +0100
From: nobull@mail.com
Subject: Re: CGI with conditional GET
Message-Id: <u91yq5rpqz.fsf@wcl-l.bham.ac.uk>

Benjamin Goldberg <goldbb2@earthlink.net> writes:

> The http 1.0 standard descripes how a conditional GET can be done, using
> an if-modified-since field in the request header.
> 
> If I'm writing a CGI which uses GET (not post), and generates all data
> from it's parameters (no external files, nothing which comes from
> outside the script), then I always want to respond "304 not modified"
> in response to a request that has an if-modified-since header, since the
> requester obviously has whatever it is that I might send him (unless the
> script changes).  How do I test for the existance of this header?

This has very little to do with Perl.  For the most part HTTP request
headers are passed CGI scripts as upcased environment variables with
an 'HTTP_' prefix and all '-' tanslated to '_'.  In Perl they can be 
accessed directly via %ENV or more neatly via CGI.pm's http() method.

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


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

Date: 04 May 2001 11:52:57 -0400
From: Vinny Murphy <vmurphy@Cisco.Com>
Subject: Re: Compare 2 arrays
Message-Id: <m366fhdsbq.fsf@vpnrel.cisco.com>

"Daniel W. Burke" <dwb1@home.com> writes:

> Hello,
> 
> I have an irritating problem... I'm trying to come up with an efficient
> way to sync 2 tables, in different databases, that have become horrible
> un-sync'd :(
> 
> So far, I've pulled the id's into 2 different files created by the
> Storable module, but now I need to figure out how to sync the id's...
> 
> Is there any "easy" or fast way to compare the 2 lists?  I want to
> get the extra id's from list A, and add those records to list B, but
> at the same time get the extra id's from list B and delete those
> records from list A.  (I hope I'm explaining myself clearly).
> 
> Right now I stored the lists as arrays, but I could re-get the data
> and store them into hashes if that is easier to manipulate...
> 
> FYI- there's over 600000 id's in each list.
> 
> Any help would be great!

Your best bet would be to look at _Algorithms in Perl_ chapter six,
which is all about sets.  You can get some excellant code out of there
to solve your problem.  Good luck.

-- 
Vinny


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

Date: Fri, 04 May 2001 16:00:59 GMT
From: "Daniel W. Burke" <dwb1@home.com>
Subject: Re: Compare 2 arrays
Message-Id: <Pine.LNX.4.20.0105041211380.4614-100000@ethyl.addictmud.org>

On 4 May 2001, Vinny Murphy wrote:

> > I have an irritating problem... I'm trying to come up with an efficient
> > way to sync 2 tables, in different databases, that have become horrible
> > un-sync'd :(
> > 
> > So far, I've pulled the id's into 2 different files created by the
> > Storable module, but now I need to figure out how to sync the id's...
> 
> Your best bet would be to look at _Algorithms in Perl_ chapter six,
> which is all about sets.  You can get some excellant code out of there
> to solve your problem.  Good luck.
> 

It looks like a book worth having, I'll have to pick that one up.

Thanks!

Dan.




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

Date: 4 May 2001 11:24:21 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Compare 2 arrays
Message-Id: <9cul3l$76r$1@boomer.cs.utexas.edu>

In article <Pine.LNX.4.20.0105041020240.4345-100000@ethyl.addictmud.org>,
Daniel W. Burke <dwb1@home.com> wrote:
>I have an irritating problem... I'm trying to come up with an efficient
>way to sync 2 tables, in different databases, that have become horrible
>un-sync'd :(
>
>So far, I've pulled the id's into 2 different files created by the
>Storable module, but now I need to figure out how to sync the id's...
>
>Is there any "easy" or fast way to compare the 2 lists?  I want to
>get the extra id's from list A, and add those records to list B, but
>at the same time get the extra id's from list B and delete those
>records from list A.  (I hope I'm explaining myself clearly).

I don't see how this would bring things into sync.  If B has some
("extra") records in it and you delete those from A, then when you're
done, B is going to have things that A doesn't.

>Right now I stored the lists as arrays, but I could re-get the data
>and store them into hashes if that is easier to manipulate...
>
>FYI- there's over 600000 id's in each list.

I wrote a script somewhat like this one time.  My goal was to cause one
table (a copy) to become exactly like another (an original).  The idea
was to make changes to the one, review them, declare them good, and
then push them to the second without completely reloading the table.

What I did was I figured out which fields I needed to compare to see if
two rows were identical.  Then, I started *two* queries at the same
time, which both looked something like this:

	select Field1, Field2 from TableA order by Field1, Field2
	select Field1, Field2 from TableB order by Field1, Field2

Then, I read one row from each table, and I compared the order of the
(sets of) keys from each table.  If the keys I just got from TableA
were greater than the ones from TableB, that meant that TableB didn't
have the row that TableA did.  So, I wrote that information to a
temporary file[1][2] and then read another row from tableB.

To look at it another way, what I did was try to read both tables in
order (by some set of keys) at the same time and hope that I got
exactly the same thing.  If I found that one table had a gap, I'd keep
reading the other table until I'd skipped over the gap in the first.

The nice thing about this approach is that it doesn't use a lot of
memory.  Just one row (or part of one row) from each table was stored
in memory at any time.  Everything else was stored in a temporary file,
and when I was done with the compare phase, I read the temporary file
to figure out what deletes and inserts I needed to do.

(I believe I always did the deletes first, in case one of the things I
needed to delete/insert was a row with a certain autoincrementing
unique primary key; that way, by the time I got around to the insert, I
should have made an opening for what I was going to insert.)

Hope that helps.

  - Logan

[1]  Using Data::Dumper, actually.  I was then able to read these
     temporary files in by reading a line and doing "eval" on it.

[2]  Actually, I created three temporary files: one for rows that
     needed to be inserted, one for those that needed to be deleted,
     and one for those that needed to be updated.  I determined which
     ones needed to be updated by actually defining two sets of
     fields.  One was those fields that, if they are the same, indicate
     that a row corresponds to a row in another table, and the other
     was those fields that should be updated between matching rows if
     they aren't already identical.
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Fri, 4 May 2001 10:09:27 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: Compare 2 arrays
Message-Id: <3af2e248@news.microsoft.com>

"Daniel W. Burke" <dwb1@home.com> wrote in message
news:Pine.LNX.4.20.0105041020240.4345-100000@ethyl.addictmud.org...
> Is there any "easy" or fast way to compare the 2 lists?  I want to
> get the extra id's from list A, and add those records to list B, but

So, in other words here you want (abstract free-style notation):
    @B += @A - @B

> at the same time get the extra id's from list B and delete those
> records from list A.  (I hope I'm explaining myself clearly).

And here it is
    @A -= @B - @A

You may want to check the perlfaq4:
    "How do I compute the difference of two arrays? How to I compute the
intersection of two arrays?"

jue




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

Date: Fri, 4 May 2001 12:22:55 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Compare 2 arrays
Message-Id: <slrn9f5lqv.4k6.tadmc@tadmc26.august.net>

Ron Hill <hillr@ugs.com> wrote:

>I have the same problems keeping 2 directories in sync


   http://rsync.samba.org/


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


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

Date: 04 May 2001 17:30:29 +0100
From: nobull@mail.com
Subject: Re: connect timeouts
Message-Id: <u9g0elrs9m.fsf@wcl-l.bham.ac.uk>

"Paul Brown" <paul.brown@ukinternetsites.com> writes:

> I use connect(S, $serverhostname) to connect to the other server, however if
> the server is down and not responding very fast, then it can sit there for a
> long time.  I want to setup some kind of timeout, so it trys to connect and
> if it hasn't connected in 30 seconds (for example), it exits.
> 
> Any solutions to create a timeout?  Thanks in advance!

See FAQ: "How do I timeout a slow event?"

Also you may consider moving to the Perl5 OO idiom for sockets
(IO::Socket).  Appart from numerous other advantages it supports
timeouts on connects.

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


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

Date: Fri, 04 May 2001 08:55:35 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <3AF2D0F7.E25385CC@stomp.stomp.tokyo>

"Randal L. Schwartz" wrote:
 
> Godzilla! wrote:
 
> > use LWP::Simple;
 
> > $image = get ("url/path/to/image.jpg");
 
> > binmode STDOUT;
 
> Of course, binmode on STDOUT has nothing to do with the following
> code.  It's a red herring.  Waste of characters.  Distracting.
> Vestigial no doubt.


Well shoot Randal, as a teenager, I lost my vestigial
in the backseat of a '63 Chevy Impala, hence my daughter.

 
> > open (FILEHANDLE, ">image.jpg");

> You need to insert binmode FILEHANDLE in here.
 
> > print FILEHANDLE $image;
> > close (FILEHANDLE);
 
> The rest of Kira's advice is sound, however.

Much to my annoyance, neither my mind nor my rearend
are as sound as my advice. 

* notices Randal raises an eyebrow *

Thanks for pointing out my error.

Godzilla!


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

Date: Fri, 04 May 2001 09:16:48 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Downloading images with HTTP/LWP libraries
Message-Id: <3AF2D5F0.C28B1737@stomp.stomp.tokyo>

Bart Lateur wrote:
 
> Godzilla! wrote:
 
> >binmode STDOUT;
> >open (FILEHANDLE, ">image.jpg");
> >print FILEHANDLE $image;
 
> Whoops, wrong filehandle.

Perhaps I should have used a broomhandle. This
would be more fitting for my personality.

> And use binmode() after the file has been
> opened.

Yeah, Randal robbed me of my vestigial on this one.
Ya know, I thought something didn't look right but
I couldn't think of what. I glanced through some of
my books but failed to find my mistake.

Ok, I confess. I didn't do as much homework as
I should have. I will write on my chalkboard,
one-hundred times, "I will do my homework."

This reminds me of our two-room schoolhouse
teacher back in Oklahoma, when I was young
and still a vestigial.

She instructed me to write on her chalkboard,
one hundred times, "I will not talk in class."
Fine. Ok.

Instead of writing horizontally, I found it quicker
to write vertically...

I will not talk
I will not talk
I will not
I will not
I will not
 ...

As our Good Lord would have it, She sent a devilish
angel to whisper in our teacher's ear. I was caught,
her chalkboard erased and, I had to write my punishment
horizontally five-hundred times along with gritting
my teeth during a switching by my Grandpa at home,
later in the day. Devilish whispered messages do
tend to spread fast and far.

I never did stop talking in class. I became more 
efficient at not being caught, just as I became
more efficient at writing punishment on her old
chalkboard, bless her heart. A fine woman she is.


Try this chalkboard punishment today and, as a teacher,
you will find yourself in civil court facing litigation
for emotionally abusing a student.

* thinks today's parents need a Grandpa switching *

Godzilla!


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

Date: Fri, 04 May 2001 15:37:56 GMT
From: Hans Kristian Eriksen <h.k.k.eriksen@astro.uio.no>
Subject: File transfers
Message-Id: <m3itjhb4q5.fsf@beregond.localdomain>

Hello.

I'm writing a server/client program which sends information back and
forth over a socket. Most of the information is just plain numbers or
text strings, but sometimes I also have to transfer binary files. So
the process looks something like this:

send number/text
send number/text
send file
send number/text
send number(text

The single numbers and text strings are sent like this:

print Client $info;
$info = <Server>;

but the files are more difficult. I'm trying to do something like:

server:

open(IN, "$filename");
while (read(IN, $buf, 1024)) {
   print Client $buf;
}
close(IN);

client:

open(OUT, ">$filename");
while ($buf = <Server>) {
   print OUT $buf;
}
close(OUT);

And it works. If I dont send anything over the socket after the file
transfer! And this is not acceptable for the rest of the program.

How do I fix this problem? I've tried several solutions, but generally
I end up with 8 bytes too much or too little on the copied file. I
have a feeling the EOF is not transferred (or written to the
destination), but I don't know how to fix it.

Can somebody help me?

Best regards,

Hans Kristian Eriksen


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

Date: Fri, 04 May 2001 13:41:38 -0400
From: "Fournier, Christopher [CAR:5H51:EXCH]" <cfour@americasm01.nt.com>
Subject: GDBM::reorganize?
Message-Id: <3AF2E9D2.36668DEB@americasm01.nt.com>

I'm using a gdbm database in this one project (tentatively, as I will be
going to MySQL), and I'm having a problem with file bloat. I have about
300k worth of textual data (upon extraction), and somehow, the database
file has grown to about 80megs. I understand that gdbm doesn't
inherently recover lost space, and that the GDBM::reorganize function is
supposed to help this. My problem is that I can't find any documentation
on this function, nor does it work on invocation. Does anyone know how
to clean up the contents of the databse? Any help would be greatly
appreciated.

Thanks!

Chris Fournier


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

Date: Fri, 04 May 2001 13:50:53 -0400
From: "Fournier, Christopher [CAR:5H51:EXCH]" <cfour@americasm01.nt.com>
Subject: Re: GDBM::reorganize?
Message-Id: <3AF2EBFD.EA27A90B@americasm01.nt.com>

Er, nm. I wasn't thinking. I just copied the non-zero data into a new
database file, and it shrank to about 500k.

-CF

"Fournier, Christopher [CAR:5H51:EXCH]" wrote:
> 
> I'm using a gdbm database in this one project (tentatively, as I will be
> going to MySQL), and I'm having a problem with file bloat. I have about
> 300k worth of textual data (upon extraction), and somehow, the database
> file has grown to about 80megs. I understand that gdbm doesn't
> inherently recover lost space, and that the GDBM::reorganize function is
> supposed to help this. My problem is that I can't find any documentation
> on this function, nor does it work on invocation. Does anyone know how
> to clean up the contents of the databse? Any help would be greatly
> appreciated.
> 
> Thanks!
> 
> Chris Fournier


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

Date: Fri, 04 May 2001 17:33:44 GMT
From: sporkboy@Spork.na (Spork Boy)
Subject: leftover Close Wait sockets
Message-Id: <slrn9f5pvn.rst.sporkboy@Spork.na>

I'm using perl to access a WinampRC running on a windows machine from my
Linux machine. It works great, with the exception that it's leaving "Close
Wait" sockets open on the windows machine. The original windows client for
the server doesn't send any kind of a goodbye command to disconnect as far
as I can tell, nor does it leave the Close Wait sockets open. Anybody know
what could be causing this?

-- 
+---------------+
|     Spork Boy | "Does this LOOK like Heaven?"
| AIM: Sporkite | 	--Johnny The Homicidal Maniac
|   ICQ: 859886 |
+---------------+


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

Date: Fri, 4 May 2001 11:40:34 -0400
From: "Mauricio Leiva" <mauricio.leiva@ubinet.cl>
Subject: newbie questions
Message-Id: <Q1AI6.709$uh.1399@news-santiago.gip.net>

Hi

I have two questions

1) Mi configurations are Linux, Apache, Perl
    Q:   How can I know if DBI and DBD::Oracle modules are ready install

2) Q:   Where can get this newsgroup FAQ

thanks

in native lang ------
Tengo dos preguntas :

1) Mi configuración es Perl, Apache, Linux.
    Cómo puedo saber si están instalados los módulos DBI y DBD para conexión
a oracle ?

2) donde puedo obtener el FAQ de este grupo de noticias ?

gracias.
--
Mauricio Leiva
Mauricio.Leiva@ubinet.cl




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

Date: 04 May 2001 18:08:14 +0100
From: nobull@mail.com
Subject: Re: newbie questions
Message-Id: <u94rv1rqip.fsf@wcl-l.bham.ac.uk>

"Mauricio Leiva" <mauricio.leiva@ubinet.cl> writes:

> Subject: newbie questions

Please use your subject line to tell us about the subject of your
post.

BTW: Arround here you subject line is read as "person too lazy to read
manuals is too lazy to think about his subject line"

> I have two questions

Please do not ask unrelated questions in the same post.
 
> 1) Mi configurations are Linux, Apache, Perl
>     Q:   How can I know if DBI and DBD::Oracle modules are ready install

Try using them and see if you get an error saying they are not.

perl -MSomeModule -e ''

> 2) Q:   Where can get this newsgroup FAQ

Look for postings with "FAQ" in their title.

You'll find it's the same one you've already got in the standard
documentation that comes with Perl.

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


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

Date: Fri, 04 May 2001 15:33:20 GMT
From: "King Fu" <kingfu@blueyonder.co.uk>
Subject: Perl and MySQL problem
Message-Id: <4ZzI6.18$Sc.3094@news1.cableinet.net>

hi ive got a strange problem i cant seem to work out, im trying to update a
field for a certain in a mysql database using the insert sql command, most
of the time this works fine but on occastion i find that all the field for
all the records in the table have been updated!!! Im not sure why this is
occuring, its a cgi script so is obvously occuring under certain
circumstances when a visitor does a certain thing but without knowing what
they do im kinda screwed!
heres the snippit of what appears to be the problem code

$sth=$dbh->prepare("SELECT name from downloads WHERE name LIKE '%$name%';")
|| die "Prepare failed: $DBI::errstr\n";
$sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
$foundMatch=0;
$foundMatch=$sth->rows();

#if a match is found increment the number of downloads for the file
if($foundMatch)
{
  $sth=$dbh->prepare("SELECT downloads from downloads WHERE name LIKE
'%$name%';") || die "Prepare failed: $DBI::errstr\n";
  $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
  $downloads=$sth->fetchrow_array();
  $downloads++;
  #save the new downloads var to the database
  $sth=$dbh->prepare("UPDATE downloads SET downloads=$downloads WHERE name
LIKE '%$name%';") || die "Prepare failed: $DBI::errstr\n";
  $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
  &printNewDownloadWindow;
}

This section of code is only run once per cgi session so as you can see im
quite baffled how it updates every record of teh table! Espcially as seeing
theirs a few hundred records which shouldnt ever be touched for quite some
time.




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

Date: Fri, 04 May 2001 15:55:52 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Perl and MySQL problem
Message-Id: <slrn9f5hvv.lfe.trammell@bayazid.hypersloth.net>

On Fri, 04 May 2001 15:33:20 GMT, King Fu <kingfu@blueyonder.co.uk> wrote:

[snip]

> ... but on occastion i find that all the field for
> all the records in the table have been updated!!!
[snip]

> #if a match is found increment the number of downloads for the file
> if($foundMatch)
> {
>   $sth=$dbh->prepare("SELECT downloads from downloads WHERE name LIKE
> '%$name%';") || die "Prepare failed: $DBI::errstr\n";
>   $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
>   $downloads=$sth->fetchrow_array();
>   $downloads++;
>   #save the new downloads var to the database

>   $sth=$dbh->prepare("UPDATE downloads SET downloads=$downloads WHERE name
> LIKE '%$name%';") || die "Prepare failed: $DBI::errstr\n";
>   $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";

Looks like $name is empty at some point.  How about a test like

  unless ($name) { die "name not defined..." }

-- 
[W]hen the manager knows his boss will accept status reports without
panic or preeemption, he comes to give honest appraisals.
                               - F. Brooks, _The Mythical Man-Month_


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

Date: 04 May 2001 12:09:09 -0400
From: Vinny Murphy <vmurphy@Cisco.Com>
Subject: Re: Perl and MySQL problem
Message-Id: <m31yq5drkq.fsf@vpnrel.cisco.com>

"King Fu" <kingfu@blueyonder.co.uk> writes:

> hi ive got a strange problem i cant seem to work out, im trying to update a
> field for a certain in a mysql database using the insert sql command, most
> of the time this works fine but on occastion i find that all the field for
> all the records in the table have been updated!!! Im not sure why this is
> occuring, its a cgi script so is obvously occuring under certain
> circumstances when a visitor does a certain thing but without knowing what
> they do im kinda screwed!
> heres the snippit of what appears to be the problem code
> 
> $sth=$dbh->prepare("SELECT name from downloads WHERE name LIKE '%$name%';")
> || die "Prepare failed: $DBI::errstr\n";

If $name has no value than '%%' in SQL will match every name, thus an
update to all records.

HTH.


-- 
Vinny


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

Date: Fri, 4 May 2001 12:19:54 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl and MySQL problem
Message-Id: <slrn9f5lla.4k6.tadmc@tadmc26.august.net>

John Joseph Trammell <trammell@bayazid.hypersloth.invalid> wrote:

>Looks like $name is empty at some point.  How about a test like
>
>  unless ($name) { die "name not defined..." }


That does not test if name is empty. That tests if name is true,
but the die reports defined instead..

"true", "empty" and "defined" mean different things, and require
different tests. Your's above tests if $name is "true", err "false"
since you have inverted the "if" to an "unless".


   unless ( length $name ) ...

_That_ tests if $name is "empty" (and also does not fail if $name should
happen to have a value of "0".


   unless ( defined $name )

That tests if $name is defined.


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


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

Date: Fri, 04 May 2001 17:34:18 GMT
From: trammell@bayazid.hypersloth.invalid (John Joseph Trammell)
Subject: Re: Perl and MySQL problem
Message-Id: <slrn9f5nof.m34.trammell@bayazid.hypersloth.net>

On Fri, 4 May 2001 12:19:54 -0400, Tad McClellan <tadmc@augustmail.com> wrote:
> John Joseph Trammell <trammell@bayazid.hypersloth.invalid> wrote:
[snip]

Mea culpa.  I plead insufficient caffeine.

-- 
[W]hen the manager knows his boss will accept status reports without
panic or preeemption, he comes to give honest appraisals.
                               - F. Brooks, _The Mythical Man-Month_


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

Date: Fri, 04 May 2001 16:15:06 GMT
From: "King Fu" <kingfu@blueyonder.co.uk>
Subject: Perl and Mysql
Message-Id: <eAAI6.99$Sc.9091@news1.cableinet.net>

Sorry if ive posted this twice but it didnt seem to work the last time as
ive been having trouble with my newserver:


hi ive got a strange problem i cant seem to work out, im trying to update a
field for a certain in a mysql database using the insert sql command, most
of the time this works fine but on occastion i find that all the field for
all the records in the table have been updated!!! Im not sure why this is
occuring, its a cgi script so is obvously occuring under certain
circumstances when a visitor does a certain thing but without knowing what
they do im kinda screwed!
heres the snippit of what appears to be the problem code

$sth=$dbh->prepare("SELECT name from downloads WHERE name LIKE '%$name%';")
|| die "Prepare failed: $DBI::errstr\n";
$sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
$foundMatch=0;
$foundMatch=$sth->rows();

#if a match is found increment the number of downloads for the file
if($foundMatch)
{
  $sth=$dbh->prepare("SELECT downloads from downloads WHERE name LIKE
'%$name%';") || die "Prepare failed: $DBI::errstr\n";
  $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
  $downloads=$sth->fetchrow_array();
  $downloads++;
  #save the new downloads var to the database
  $sth=$dbh->prepare("UPDATE downloads SET downloads=$downloads WHERE name
LIKE '%$name%';") || die "Prepare failed: $DBI::errstr\n";
  $sth->execute() || die "Coultdnt execute query: $DBI::errstr\n";
  &printNewDownloadWindow;
}

This section of code is only run once per cgi session so as you can see im
quite baffled how it updates every record of teh table! Espcially as seeing
theirs a few hundred records which shouldnt ever be touched for quite some
time.






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

Date: Fri, 4 May 2001 16:28:43 +0100
From: "Lee" <Home@LeeGoddard.com>
Subject: Poetry::Aum version 0 released
Message-Id: <FUzI6.593$Wp1.9930@NewsReader>

package Poetry::Aum;
use strict;
use warnings;
our $VERSION = 0;

sub new {
 my $self = new Abstract::Entity(rand);
 my $ego  = new Abstract::Concept;
 my $goal = new Abstract::Interest;
 our $philosophy;

 DARK_NIGHT:
 while (defined $goal){
  $philosophy = <STDIN>;
  study $philosophy;
  if ($ego->understands($philosophy)){
   undef $goal; # implies last DARK_NIGHT;
  }
 }

 $self->{$philosophy} = localtime;
 bless $self; # Intentionally classless
 return;   # Does this hand over my $self?
}

1;





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

Date: Fri, 04 May 2001 17:10:38 GMT
From: "Eric" <mail@NOSPAMericmarques.net>
Subject: Re: Printing HTTP headers/body in perl
Message-Id: <ioBI6.30399$PF4.55396@news.iol.ie>

thanks that showed the body of the http request but not the rest


--
Eric Marques
mail@ericmarques.net

"Jon Ericson" <Jonathan.L.Ericson@jpl.nasa.gov> wrote in message
news:86zoctkccw.fsf@jon_ericson.jpl.nasa.gov...
> "Eric" <mail@NOSPAMericmarques.net> writes:
>
> > I want to make a perl script
> > to show the headers/content the browser sends to the script in the http
> > request
> > i dont mean to just print the environment variables
> > i want to read the exact headers/body everything the browser sends to
the
> > script
>
> I am sure consulting the documentation, FAQ and forums for CGI would
> be revealing.
>
> > i have an idea that this info is in the STDIN
> > i tried
> > print STDIN;
> > but it didnt work printed nothing
>
> Perhaps you meant:
>
>   print <STDIN>;
>
> Jon




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

Date: Fri, 04 May 2001 11:04:09 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Printing HTTP headers/body in perl
Message-Id: <3AF2EF19.4E20029E@stomp.stomp.tokyo>

Eric wrote:

(snipped)

> I want to make a perl script to show the headers/content the
> browser sends to the script in the http request...


There are free scripts to be downloaded from our internet
to perform this function, if you spend a little time
looking around.

Tim Meadowcroft has one available at his site which
would serve as an excellent example of how to write
a script for your task.

HttpSniffer v2.14 written by Tim Meadowcroft.

This script is available via:

http://www.schmerg.com/code.asp

Actual code source is located here:

http://www.schmerg.com/HttpSniffer.pl.txt


I have a copy of his version 2.5 available
for the next ten days after which, I will
remove it from my site:

http://la.znet.com/~callgirl/sniffer.html


I do not know why his more recent version
is no longer available at his site.

Godzilla!


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

Date: 04 May 2001 17:18:08 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u9n18trsu7.fsf@wcl-l.bham.ac.uk>

Now here's an odd thing... the subject of this thread has now mutated
to so that it _does_ now match the subject line!

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

>     if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
>     {
>         return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
>     }

$1 is a global variable.  This means that when the subroutine is
executed it will use whatever value happens to be in $1 at the time.
This is no good as you want the closure to remeber the string that was
found in the regex.  You must use a lexical variable instead.

 if (my ($sortkey) = $path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
 {
    return sub { $hohref -> {$a} -> {$sortkey} cmp $hohref -> {$b} -> {$sortkey} };
 }

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


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

Date: 04 May 2001 17:27:25 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u9k83xrseq.fsf@wcl-l.bham.ac.uk>

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

> Joe Schaefer wrote:
> > 
> > "Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:
> > 
> > >     if ($path =~ /\/(\w+)$/)                 # sort by string in PATH_INFO
> > >     {
> > >         return sub { $hohref -> {$a} -> {$1} cmp $hohref -> {$b} -> {$1} };
> >                                            ^^                          ^^
> > 
> > Like $a and $b, $1 is a global, so it not evaluated until the closure is
> > *executed*. Since you need it to be evaluated at compile time, stuff it in
> > a lexical first:
> > 
> >   if ($path =~ /\/(\w+)$/) {
> >     my $match = $1;
> >     return sub { $hohref->{$a}->{$match} cmp $hohref->{$b}->{$match} };
> >   }
> 
> Thank you, it has finally explained what happens to me.
> I didn't realize, that sub { ... } evaluates only the
> lexical (and not dyn.) variables during the compile time.

No sub { ... } does not cause any variables to evaluated.

An anonymous[1] subroutine behaves as a _closure_ with respect to
lexically scoped variable.  That is to say that in the above code each
time execution passes the statement "my $match=$1" a new variable
called $match is created.  The anonymous subroutine remebers which
particular varaible is referred to by the name $match at the time.
It does not remember the contents of the variable.

[1] Actually named ones do too and this is why nesteded subroutines and
subroutines declared in loops often don't DWIM in Perl.

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


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

Date: 04 May 2001 17:30:18 +0100
From: nobull@mail.com
Subject: Re: Problem with the subroutine (closure?) for the "sort"
Message-Id: <u9hez1rs9x.fsf@wcl-l.bham.ac.uk>

"Alexander Farber (EED)" <eedalf@eed.ericsson.se> writes:

> nobull@mail.com wrote:
> > > and I also suspect that $a and $b are undefined anyway...
> > 
> > This is another problem.  $a and $b are package variables providing
> > sort_sub() is defined in the same package as the call to sort()
> > there's no problem.
> > 
> > If you want sort to use a comparison routine in another package then
> > see thread "Using a comparison routine in another package" from last
> > November or more recently "efficient comparators (namespaces for $a and
> > $b)" a few weeks ago.
> 
> Thanks but your solution looks really dirty :-(

There is a clean (but slower) solution using @_[0,1] rather than $a,$b
too but since as far as I can see you are not using a comparison routine
in another package so the issue does not arrise.

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


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

Date: Fri, 04 May 2001 09:03:59 -0700
From: Robert Fonda <rlf@proimages.net>
Subject: Problems with Crypt::Blowfish/Crypt::CBC
Message-Id: <3AF2D2EF.25CDB23@proimages.net>

I have down loaded all the requisite modules. I can run the CBC make
test and it works. My problem lies in the Crypt::Blowfish CBC goo. I AM
RUNNING Crypt-CBC-1.25 AND BLOWFISH 2.06. So as far as I know I meet the
requirements. Everything else tests fine. The CBC module tests fine,
but.........

when I do the make, then the make test, I get the following error (It's
at the bottom):

root@rodan:/usr/local/src/Crypt-Blowfish-2.06# make test
PERL_DL_NONLAZY=1 /usr/local/bin/perl -Iblib/arch -Iblib/lib
-I/usr/local/lib/perl5/5.6.1/i586-linux -I/usr/local/lib/perl5/5.6.1
test.pl
1..11
ok 1
ok 2
ok 3
ok 4
DEP: 0000000000000000  <-- should be 0000000000000000
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10

Running standard mode speed tests.. encrypting with non-cached cipher
5,000 cycles:  6 wallclock secs ( 5.51 usr +  0.03 sys =  5.54 CPU)

Running standard mode speed tests.. decrypting with non-cached cipher
5,000 cycles:  5 wallclock secs ( 5.50 usr +  0.07 sys =  5.57 CPU)

Running standard mode speed tests.. encrypting with cached cipher
10,000 cycles:  1 wallclock secs ( 0.65 usr +  0.00 sys =  0.65 CPU)

Running standard mode speed tests.. decrypting with cached cipher
10,000 cycles:  1 wallclock secs ( 0.61 usr +  0.00 sys =  0.61 CPU)

******** ERROR HERE *********
Testing Cipher Block Chaining..
Error (probably harmless):
CBC mode requires Crypt::CBC version 1.22 or higher.
******** ERROR HERE *********


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

Date: 04 May 2001 18:02:57 +0100
From: nobull@mail.com
Subject: Re: Rename subdirectories and files
Message-Id: <u97kzxrqri.fsf@wcl-l.bham.ac.uk>

Arun Horne <a.b.horne@exeter.ac.uk> writes:

> Hi I want to rename an entire directory tree in one go such that:
> 
> all whitespace is replaced by _'s
> each word in the filename is correctly capitalised, i.e. HeLLo becomes
> Hello and jOb -> Job

Which bit are you having trouble with?

Knowing that File::Find is the Perl module to traverse directory
trees?

Knowing that the Perl rename() function is used to rename files?

Writing a s/(\w+)/\u\L\1/g ?

Writing s/\s+/_/g or did you mean tr/ /_/ ?

Knowing the first thing about Perl?

> Can anyone provide me with such code?

Yep, a lot of the people here work as Perl consultants for an hourly
rate and if you want Perl code written for you rather than advice on
how to write Perl yourself then they may help for a fee.

On the whole people in this group prefer not to help people who appear
to be freeloading rather than trying to learn/discuss Perl.

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


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

Date: Fri, 4 May 2001 12:26:32 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Rename subdirectories and files
Message-Id: <slrn9f5m1o.4k6.tadmc@tadmc26.august.net>

Arun Horne <a.b.horne@exeter.ac.uk> wrote:
>Hi I want to rename an entire directory tree in one go 

   use File::Find.

>such that:
>
>all whitespace is replaced by _'s

   tr/\s//d;


>each word in the filename is correctly capitalised, i.e. HeLLo becomes
>Hello and jOb -> Job

   s/(.*)/\u\L$1/;


>Can anyone provide me with such code?


Post to clpmisc for help with _writing_ Perl programs.

Use a search engine for searching for programs.


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


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

Date: Fri, 04 May 2001 13:44:36 -0400
From: Mike Song <Mike.Song@usa.net>
Subject: use Apache::Htpasswd
Message-Id: <3AF2EA84.60B1FE9F@usa.net>

Hello;

I know very little about Perl and want to set a web page with
password protection. I already installed module use Apache::Htpasswd
on my Linux box.

Anyone know of a complete example of using use Apache::Htpasswd?

Thanks
Mike



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

Date: Fri, 4 May 2001 11:58:01 -0400
From: "T_Boss" <T_boss75@curanet.com>
Subject: very big array
Message-Id: <AmAI6.209879$lj4.6007255@news6.giganews.com>

I need to compare to array's of 270 elements.
I did it like this:

foreach $mod (@tot_modem)
           foreach $f_mod (@array)
                last if $mod eq $f_mod;
                if ($f_mod eq $array[$#array])

Is there an eazier way to do this, or maybe faster?.

And how to create such big array, is there a way to continue on the next
line without closing the array?




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

Date: 04 May 2001 17:45:27 +0100
From: nobull@mail.com
Subject: Re: very big array
Message-Id: <u9ae4trrko.fsf@wcl-l.bham.ac.uk>

"T_Boss" <T_boss75@curanet.com> writes:

> Subject: very big array

Please use your subject line to tell us something about the subject of
your post.

> I need to compare to array's of 270 elements.
> I did it like this:
> 
> foreach $mod (@tot_modem)
>            foreach $f_mod (@array)
>                 last if $mod eq $f_mod;
>                 if ($f_mod eq $array[$#array])
> 
> Is there an eazier way to do this, or maybe faster?.

FAQ: "How do I compute the difference of two arrays?" 

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


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

Date: Fri, 4 May 2001 17:07:10 +0100
From: "Mike Solomon" <msolomon@3s-technology.com>
Subject: warnings from MIME-Lite
Message-Id: <9cuk3h$5m0$1@taliesin.netcom.net.uk>

When I run a script that uses MIME-Lite to send E-mail I get the following
warnings :

Use of uninitialized value in substitution (s///) at
        D:/Perl/site/lib/MIME/Lite.pm line 998 (#1)

    (W uninitialized) An undefined value was used as if it were already
defined.
  It was
    interpreted as a "" or a 0, but maybe it was a mistake.  To suppress
this
    warning assign a defined value to your variables.

Use of uninitialized value in scalar assignment at
        D:/Perl/site/lib/Net/Domain.pm line 193 (#1)
Use of uninitialized value in pattern match (m//) at
        D:/Perl/site/lib/Net/Domain.pm line 217 (#1)
Use of uninitialized value in split at D:/Perl/site/lib/Net/Domain.pm line
221 (
#1)
Use of uninitialized value in concatenation (.) at
        D:/Perl/site/lib/MIME/Lite.pm line 1889 (#1)

Without disabling diagnostics or editing Lite.pm and Domain.pm, is there any
way to disable these messages ?


Regards


Mike Solomon




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

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


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