[23281] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5501 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 14 18:05:45 2003

Date: Sun, 14 Sep 2003 15:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 14 Sep 2003     Volume: 10 Number: 5501

Today's topics:
    Re: $SIG{__DIE__} doesn't make sense when using CGI::Ca <nospam-abuse@ilyaz.org>
        Clean user input from CGI for output to WIN32::ODBC (Max Harvey)
    Re: Clean user input from CGI for output to WIN32::ODBC <mpapec@yahoo.com>
    Re: Clean user input from CGI for output to WIN32::ODBC <r_reidy@comcast.net>
    Re: Clean user input from CGI for output to WIN32::ODBC <jwillmore@cyberia.com>
        closed filehandle <samj@austarmetro.com.au>
    Re: closed filehandle <postmaster@castleamber.com>
    Re: closed filehandle <kuujinbo@hotmail.com>
    Re: closed filehandle <jurgenex@hotmail.com>
    Re: closed filehandle <trammell+usenet@hypersloth.invalid>
    Re: closed filehandle <samj@austarmetro.com.au>
    Re: closed filehandle <asu1@c-o-r-n-e-l-l.edu>
    Re: closed filehandle <samj@austarmetro.com.au>
    Re: closed filehandle <asu1@c-o-r-n-e-l-l.edu>
    Re: Compress/Zip a String (Malcolm Dew-Jones)
        Is Win32::OLE qw(EVENTS) ~ to the VBA "Impliments" stat (psyshrike)
        Maddening bug: Why do quotes fix it? <apollock11@hotmail.com>
    Re: Maddening bug: Why do quotes fix it? <jwillmore@cyberia.com>
    Re: Maddening bug: Why do quotes fix it? <apollock11@hotmail.com>
    Re: Maddening bug: Why do quotes fix it? <jwillmore@cyberia.com>
        Newbie Help with Hashes (James Bonanno)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 14 Sep 2003 14:21:12 +0000 (UTC)
From:  Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: $SIG{__DIE__} doesn't make sense when using CGI::Carp
Message-Id: <bk1tgo$2ad$1@agate.berkeley.edu>

[A complimentary Cc of this posting was sent to
David
<dz1976@hotmail.com>], who wrote in article <c27dfcf4.0309131952.332067f1@posting.google.com>:
> > What is the way to undo the CGI::Carp handler definitions?
> 
> technically, you can't. because CGI::Carp does its magic by
> overwritting the global die function with:
> 
> *CORE::GLOBAL::die = \&CGI::Carp::die;
> 
> once this is done, you can never get back the real die function.

Eh???  What about CORE::die()?

Ilya


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

Date: 14 Sep 2003 00:50:28 -0700
From: google@DELTAL.org (Max Harvey)
Subject: Clean user input from CGI for output to WIN32::ODBC
Message-Id: <7a09b211.0309132350.755395a0@posting.google.com>

Hi,

I have a simple script which takes input from CGI, and outputs it to a
database with WIN32::ODBC.

The problem is when I encounter input with a single quote in it, it
messes up the SQL statement for the Win32::ODBC module.

How can I clean/phrase the input ($comments), so that it can be used
as part of my SQL statement?


Any help would be great... the script basically does what it is
supposed to do, but it can be crashed by the user putting in the wrong
input, something which I know is bad, just aren't good enough with
Perl yet to fix :(



Max.


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

Date: Sun, 14 Sep 2003 10:10:05 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Clean user input from CGI for output to WIN32::ODBC
Message-Id: <5588mvgujmlbknjot7r6809ueshgmvldg4@4ax.com>

X-Ftn-To: Max Harvey 

google@DELTAL.org (Max Harvey) wrote:
>The problem is when I encounter input with a single quote in it, it
>messes up the SQL statement for the Win32::ODBC module.
>
>How can I clean/phrase the input ($comments), so that it can be used
>as part of my SQL statement?
>
>Any help would be great... the script basically does what it is
>supposed to do, but it can be crashed by the user putting in the wrong
>input, something which I know is bad, just aren't good enough with
>Perl yet to fix :(

perldoc DBI,
 $sth = $dbh->prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)");

or you can manually backslash your values.


-- 
Matija


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

Date: Sun, 14 Sep 2003 08:45:11 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: Clean user input from CGI for output to WIN32::ODBC
Message-Id: <3F647EF7.4050208@comcast.net>

Look qt quote() in perldoc DBI

Max Harvey wrote:
> Hi,
> 
> I have a simple script which takes input from CGI, and outputs it to a
> database with WIN32::ODBC.
> 
> The problem is when I encounter input with a single quote in it, it
> messes up the SQL statement for the Win32::ODBC module.
> 
> How can I clean/phrase the input ($comments), so that it can be used
> as part of my SQL statement?
> 
> 
> Any help would be great... the script basically does what it is
> supposed to do, but it can be crashed by the user putting in the wrong
> input, something which I know is bad, just aren't good enough with
> Perl yet to fix :(
> 
> 
> 
> Max.


-- 
Ron Reidy
Oracle DBA



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

Date: Sun, 14 Sep 2003 20:41:52 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Clean user input from CGI for output to WIN32::ODBC
Message-Id: <20030914164204.768ea317.jwillmore@cyberia.com>

On Sun, 14 Sep 2003 08:45:11 -0600
Ron Reidy <r_reidy@comcast.net> wrote:
> Look qt quote() in perldoc DBI
> 
> Max Harvey wrote:
> > Hi,
> > 
> > I have a simple script which takes input from CGI, and outputs it
> > to a database with WIN32::ODBC.
                                 ^^^^^^^^^^^^
> > 
> > The problem is when I encounter input with a single quote in it,
> > it messes up the SQL statement for the Win32::ODBC module.
> > 
> > How can I clean/phrase the input ($comments), so that it can be
> > used as part of my SQL statement?
> > 
> > 
> > Any help would be great... the script basically does what it is
> > supposed to do, but it can be crashed by the user putting in the
> > wrong input, something which I know is bad, just aren't good
> > enough with Perl yet to fix :(

Actually, the OP needs to use WIN32::DBIODBC, then he can look up the
'quote' method.  There is no 'quote' method in WIN32::ODBC, I think. 
Or, simply switch to DBI.

Just an observation :)

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Idaho state law makes it illegal for a man to give his sweetheart
a box of candy weighing less than fifty pounds. 


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

Date: Sun, 14 Sep 2003 09:36:27 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: closed filehandle
Message-Id: <3f64369a@news.comindico.com.au>

Hello
when I run the code below I get
readline() on closed filehandle DATA at practice.plx line 6.

#!/usr/bin/perl

use warnings;

use strict;

open DATA, 'home/username/data/avg' || die $!;

while (<DATA>) {

print $_;

}




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

Date: Sun, 14 Sep 2003 11:45:17 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: closed filehandle
Message-Id: <1063532830.462657@halkan.kabelfoon.nl>

Sam wrote:

> Hello
> when I run the code below I get
> readline() on closed filehandle DATA at practice.plx line 6.
>

line numbers added

1 #!/usr/bin/perl
2
3 use warnings;
4
5 use strict;
6
7 open DATA, 'home/username/data/avg' || die $!;
8
9 while (<DATA>) {
10
11 print $_;
12
13 }

Doubt it.

-- 
Kind regards,       feel free to mail: mail(at)johnbokma.com (or reply)
                     virtual home: http://johnbokma.com/  ICQ: 218175426
John                web site hints: http://johnbokma.com/websitedesign/



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

Date: Sun, 14 Sep 2003 21:55:23 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: closed filehandle
Message-Id: <bk1oei$hat$1@pin3.tky.plala.or.jp>

Sam wrote:
> Hello
> when I run the code below I get
> readline() on closed filehandle DATA at practice.plx line 6.
> 
> #!/usr/bin/perl
> 
> use warnings;
> 
> use strict;
> 
> open DATA, 'home/username/data/avg' || die $!;
> 
> while (<DATA>) {
> 
> print $_;
> 
> }
> 
> 

You need to be specific when passing file/path names to open(). Unless 
the  script is running from your home directory (you passed a relative 
path), it won't work. Try:

open DATA, '/home/username/data/avg' || die $!;

HTH - keith



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

Date: Sun, 14 Sep 2003 13:47:14 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: closed filehandle
Message-Id: <Cj_8b.11126$NX3.9947@nwrddc01.gnilink.net>

Sam wrote:
> when I run the code below I get
> readline() on closed filehandle DATA at practice.plx line 6.
>
> use warnings;
> use strict;
> open DATA, 'home/username/data/avg' || die $!;

There are two problems in this one line:
Due to precedence rules it will be evaluated as
    open DATA, ('home/username/data/avg' || die $!);

If you change this to
    open DATA, 'home/username/data/avg' or die $!;
then probably you will get a runtime error "File does not exist" which
points to the second problem:
I'm guessing but probably you meant to open '/home/username/data/avg', not
just 'home/username/data/avg'.

jue




> while (<DATA>) {
> print $_;
> }




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

Date: Sun, 14 Sep 2003 15:16:41 +0000 (UTC)
From: "John J. Trammell" <trammell+usenet@hypersloth.invalid>
Subject: Re: closed filehandle
Message-Id: <slrnbm91ip.9o6.trammell+usenet@hypersloth.el-swifto.com.invalid>

On Sun, 14 Sep 2003 09:36:27 GMT, Sam <samj@austarmetro.com.au> wrote:
[snip]
> open DATA, 'home/username/data/avg' || die $!;
> 

I don't think this line does what you want it to do, because
of precedence issues.  Try instead (untested):

  open(DATA, 'home/username/data/avg') || die $!;

or:

  open DATA, 'home/username/data/avg' or die $!;

and read e.g.:

  http://www.foo.be/docs/tpj/issues/vol4_3/tpj0403-0002.html



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

Date: Sun, 14 Sep 2003 18:25:00 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: Re: closed filehandle
Message-Id: <3f64b27b@news.comindico.com.au>


"Jürgen Exner" <jurgenex@hotmail.com> wrote in message
news:Cj_8b.11126$NX3.9947@nwrddc01.gnilink.net...
> Sam wrote:
> > when I run the code below I get
> > readline() on closed filehandle DATA at practice.plx line 6.
> >
> > use warnings;
> > use strict;
> > open DATA, 'home/username/data/avg' || die $!;
>
> There are two problems in this one line:
> Due to precedence rules it will be evaluated as
>     open DATA, ('home/username/data/avg' || die $!);
>
> If you change this to
>     open DATA, 'home/username/data/avg' or die $!;
> then probably you will get a runtime error "File does not exist" which
> points to the second problem:
> I'm guessing but probably you meant to open '/home/username/data/avg', not
> just 'home/username/data/avg'.
>
> jue
>
>
>
>
> > while (<DATA>) {
> > print $_;
> > }
>
>

 #!/usr/bin/perl
 use warnings;
 use strict;

my $file = "home/user/data/avg";
 open DATA, $file or die $!;
 while (<DATA>) {
 print $_;
 }

when I run it I get
No such file or directory at practice.plx line 6.




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

Date: 14 Sep 2003 20:09:47 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: closed filehandle
Message-Id: <Xns93F6A46C9676Easu1cornelledu@132.236.56.8>

"Sam" <samj@austarmetro.com.au> wrote in
news:3f64b27b@news.comindico.com.au: 

> 
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> news:Cj_8b.11126$NX3.9947@nwrddc01.gnilink.net...
>> Sam wrote:
>> > when I run the code below I get
>> > readline() on closed filehandle DATA at practice.plx line 6.
>> >
>> > use warnings;
>> > use strict;
>> > open DATA, 'home/username/data/avg' || die $!;

<snip>

>> If you change this to
>>     open DATA, 'home/username/data/avg' or die $!;
>> then probably you will get a runtime error "File does not exist"
>> which points to the second problem:
>> I'm guessing but probably you meant to open
>> '/home/username/data/avg', not just 'home/username/data/avg'.

<snip>
> 
>  #!/usr/bin/perl
>  use warnings;
>  use strict;
> 
> my $file = "home/user/data/avg";
>  open DATA, $file or die $!;
>  while (<DATA>) {
>  print $_;
>  }
> 
> when I run it I get
> No such file or directory at practice.plx line 6.

You don't really read the responses apparently. Please read what Jurgen 
pointed out as the second problem with the open call, and see if fixing 
that solves your issue.

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Sun, 14 Sep 2003 20:47:23 GMT
From: "Sam" <samj@austarmetro.com.au>
Subject: Re: closed filehandle
Message-Id: <3f64d3da@news.comindico.com.au>


"A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message
news:Xns93F6A46C9676Easu1cornelledu@132.236.56.8...
> "Sam" <samj@austarmetro.com.au> wrote in
> news:3f64b27b@news.comindico.com.au:
>
> >
> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
> > news:Cj_8b.11126$NX3.9947@nwrddc01.gnilink.net...
> >> Sam wrote:
> >> > when I run the code below I get
> >> > readline() on closed filehandle DATA at practice.plx line 6.
> >> >
> >> > use warnings;
> >> > use strict;
> >> > open DATA, 'home/username/data/avg' || die $!;
>
> <snip>
>
> >> If you change this to
> >>     open DATA, 'home/username/data/avg' or die $!;
> >> then probably you will get a runtime error "File does not exist"
> >> which points to the second problem:
> >> I'm guessing but probably you meant to open
> >> '/home/username/data/avg', not just 'home/username/data/avg'.
>
> <snip>
> >
> >  #!/usr/bin/perl
> >  use warnings;
> >  use strict;
> >
> > my $file = "home/user/data/avg";
> >  open DATA, $file or die $!;
> >  while (<DATA>) {
> >  print $_;
> >  }
> >
> > when I run it I get
> > No such file or directory at practice.plx line 6.
>
> You don't really read the responses apparently. Please read what Jurgen
> pointed out as the second problem with the open call, and see if fixing
> that solves your issue.
>
> Sinan.
>
> -- 
> A. Sinan Unur
> asu1@c-o-r-n-e-l-l.edu
> Remove dashes for address
> Spam bait: mailto:uce@ftc.gov

yes I did read all the posts, sorry that I didn't give that impression

[Quote]*************************************
There are two problems in this one line:
Due to precedence rules it will be evaluated as
    open DATA, ('home/username/data/avg' || die $!);

If you change this to
    open DATA, 'home/username/data/avg' or die $!;
then probably you will get a runtime error "File does not exist" which
points to the second problem:
I'm guessing but probably you meant to open '/home/username/data/avg', not
just 'home/username/data/avg'.
********************************************

the suggestion to use the 'or' instead '||' has been tried for no avail, but
knowing the || has a precedence over 'or' so I used 'or' with my second
version of the program (open DATA, $file or die $!;)

the second suggestion 'guess' states (open '/home/username/data/avg'), well
where is the file handler DATA so I didn't understand how to implement that
solution.

thanks





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

Date: 14 Sep 2003 21:49:29 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: closed filehandle
Message-Id: <Xns93F6B553F2AD2asu1cornelledu@132.236.56.8>

"Sam" <samj@austarmetro.com.au> wrote in
news:3f64d3da@news.comindico.com.au: 

> 
> "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu> wrote in message
> news:Xns93F6A46C9676Easu1cornelledu@132.236.56.8...
>> "Sam" <samj@austarmetro.com.au> wrote in
>> news:3f64b27b@news.comindico.com.au:
>>
>> >
>> > "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
>> > news:Cj_8b.11126$NX3.9947@nwrddc01.gnilink.net...
>> >> Sam wrote:
>> >> > when I run the code below I get
>> >> > readline() on closed filehandle DATA at practice.plx line 6.
>> >> >
>> >> > use warnings;
>> >> > use strict;
>> >> > open DATA, 'home/username/data/avg' || die $!;
>>
>> <snip>
>>
>> >> If you change this to
>> >>     open DATA, 'home/username/data/avg' or die $!;
>> >> then probably you will get a runtime error "File does not exist"
>> >> which points to the second problem:
>> >> I'm guessing but probably you meant to open
>> >> '/home/username/data/avg', not just 'home/username/data/avg'.
>>
>> <snip>
>> >
>> >  #!/usr/bin/perl
>> >  use warnings;
>> >  use strict;
>> >
>> > my $file = "home/user/data/avg";
>> >  open DATA, $file or die $!;
>> >  while (<DATA>) {
>> >  print $_;
>> >  }
>> >
>> > when I run it I get
>> > No such file or directory at practice.plx line 6.
>>
>> You don't really read the responses apparently. Please read what
>> Jurgen pointed out as the second problem with the open call, and see
>> if fixing that solves your issue.
>>
>> Sinan.
>
> yes I did read all the posts, sorry that I didn't give that impression
> 
> [Quote]*************************************
> There are two problems in this one line:
> Due to precedence rules it will be evaluated as
>     open DATA, ('home/username/data/avg' || die $!);
> 
> If you change this to
>     open DATA, 'home/username/data/avg' or die $!;
> then probably you will get a runtime error "File does not exist" which
> points to the second problem:
> I'm guessing but probably you meant to open '/home/username/data/avg',
> not just 'home/username/data/avg'.
> ********************************************
> 
> the suggestion to use the 'or' instead '||' has been tried for no
> avail, but knowing the || has a precedence over 'or' so I used 'or'
> with my second version of the program (open DATA, $file or die $!;)
> 
> the second suggestion 'guess' states (open '/home/username/data/avg'),
> well where is the file handler DATA so I didn't understand how to
> implement that solution.

OK, maybe this is an English problem (on your part).

<quote author="Jurgen">
> I'm guessing but probably you meant to open '/home/username/data/avg',
> not just 'home/username/data/avg'.
</quote>

That is an English sentence, not a Perl statement (notice the 'you meant 
to open' part).

#!/usr/bin/perl

use warnings;
use strict;

# BTW, where is the actual file located?
open(DATA, '/home/user/data/avg') || die $!;
while (<DATA>) {
  print;
}


-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: 14 Sep 2003 01:39:12 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Compress/Zip a String
Message-Id: <3f642930@news.victoria.tc.ca>

http://edealseek.com/newsgroup.html (a@slip-12-64-158-90.mis.prserv.net) wrote:
: I need to convert a string, an URI/EmailAddress based string into a
: letter/number only string. I know I can use acsii table, but that will
: make each char into a 2 letter thing, that will increase the length of
: the string by 100%. I know there are many zip/compress algorithm for
: files. I used gzip to zip text file, and the ratio is 10%, so that
: means using a good algorithm, I can cut 90% fat. I wonder if anyone
: can show me a way to zip/compress a string (http://?&key=value, and
: something@somewhere.com like) into the least of letters/numbers

zip and then base64

zip makes it as small a possible

base64 makes it a little bigger but in ascii




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

Date: 14 Sep 2003 12:35:59 -0700
From: shrike@cyberspace.org (psyshrike)
Subject: Is Win32::OLE qw(EVENTS) ~ to the VBA "Impliments" statement?
Message-Id: <79485f9d.0309141135.1d0ee5a6@posting.google.com>

Hey, 

I need to export a client interface into a Win32 COM server, to
interact w/ an API. VB apparently does this by saying "Impliments foo"
or whatever.

Is using the the event loop with Win32::OLE the same thing, or are
there other requirements?

-TIA 
-Matt


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

Date: Sun, 14 Sep 2003 12:57:22 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Maddening bug: Why do quotes fix it?
Message-Id: <bk2h76$7nu$1@agate.berkeley.edu>

This one is driving me crazy. I have a perl cgi script,
ActiveState perl 5.8.0, running on Apache 2.0.46,
Windows 2000. The bug happens both under mod_perl and
under regular cgi perl. I found I could fix the problem
by putting the difficult variable in quotes, or applying
a trivial regular expression to it. But I want to know
why!

The program takes input from a web form and uses ADO
to add it to an Access 97 database. The difficult field
is of type 'text', not required and not indexed (although
changing these parameters in various ways didn't seem to
affect the bug). The bug is that the text string always
gets added to the database as a zero (0) UNLESS I surround
it with quotes or apply a RE to it first. Then it gets
added as the correct string! There's either something very
subtle going on here or very stupid. If it's the latter I
will take my lumps like a good sport.

I can't reproduce the problem in any other way except my
exact database and setup. The script is a bit too long to
post here so I will try and post what I hope are the two
subroutines in question (unchanged except for the addition
of the comments):

# $post_data is a hash reference containing the form data
# $rs is the open recordset object
# $conn is the open connection object
sub UpdateDatabase {
     my ($post_data, $rs, $conn) = @_;
     my $title      = $post_data->{'Event Title'};
     my $type       = $post_data->{'Event Type'};
     my $statform   = $post_data->{'Stat Form'};
     my $category   = $post_data->{'Category'};
     # $category prints: "A valid string"
     my $instructor = $post_data->{'Instructor'};
     my $staff      = $post_data->{'Staff'};
     my $dept       = $post_data->{'Department'};
     my $number     = $post_data->{'Course Number'};
     my $faculty    = $post_data->{'Faculty/GSI Name'};
     my $attendees  = $post_data->{'Attendees'};
     my $comments   = $post_data->{'Comments'};
     my $month      = $post_data->{'Month'};
     my $day        = $post_data->{'Day'};
     my $year       = $post_data->{'Year'};
     my $hour1      = $post_data->{'Start Hour'};
     my $minute1    = $post_data->{'Start Minute'};
     my $ampm1      = $post_data->{'Start AM/PM'};
     my $hour2      = $post_data->{'End Hour'};
     my $minute2    = $post_data->{'End Minute'};
     my $ampm2      = $post_data->{'End AM/PM'};
     my $date       = "$month/$day/$year";
     my $start      = "$hour1:$minute1 $ampm1";
     my $end        = "$hour2:$minute2 $ampm2";

     # Since $category is the only variable displaying this problem
     # the fact that we're doing something special with it alone here
     # is suspicious. However deleteing all of this still results in
     # in the bug.
     unless ($category) {
         if ($type eq 'Library Staff') {
             $category = "E. Library Staff";
         } else {
             $category = "C. Training";
         }
     }

     # $category prints: "A valid string"
     $post_data->{Category} = $category;
     # $category prints: "A valid string"
     # $category =~ s/(\w)/$1/g; also solves the bug

     my %fieldvalues = ("Instructor"          => $instructor,
                        "Event Title"         => $title,
                        "Event Type"          => $type,
                        "Category"            => "$category",
                        "Stat Form"           => $statform,
                        "Assisting Staff"     => $staff,
                        "Course Department"   => $dept,
                        "Course Number"       => $number,
                        "Faculty Name"        => $faculty,
                        "Number of Attendees" => $attendees,
                        "Course Event"        => $event,
                        "Date"                => $date,
                        "Time Start"          => $start,
                        "Time End"            => $end,
                        "Comments"            => $comments);
     # $category prints: "A valid string"
     # $fieldvalues{Category} prints: "A valid string"
     my ($fields, $values) = &GetFieldValues (\%fieldvalues);
     # Looping through @$fields and @$values retrieves: "A valid string"
     $rs->AddNew ($fields, $values);
     # BUG! Database field 'Category' gets 0 and not 'A valid string'
     # if $category is not in quotes above!
     &CheckDBErrors($conn, \@dberrors, "Update");
}

sub GetFieldValues {
     my $fieldvalues = shift;
     my (@fields, @values);
     foreach my $field (keys %{$fieldvalues}) {
         if ($fieldvalues->{$field} or $fieldvalues->{$field} eq "0") {
             push @fields, $field;
             push @values, $fieldvalues->{$field};
         }
     }
     return (\@fields, \@values);
}

__END__

I put in several comments that reflect the result of printing
the variable at various stages, and no matter where I put it or
which variable I am printing I always see "A valid string" which
is my test value. The only place I have EVER seen a 0 is in the
database when I don't put the quotes around $category.

So why does the simple fact of putting $category in quotes above
solve this bug?



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

Date: Sun, 14 Sep 2003 20:33:15 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Maddening bug: Why do quotes fix it?
Message-Id: <20030914163302.110ebc34.jwillmore@cyberia.com>

On Sun, 14 Sep 2003 12:57:22 -0700
Arvin Portlock <apollock11@hotmail.com> wrote:
<sniped for brevity>
> So why does the simple fact of putting $category in quotes above
> solve this bug?

No where in your post do you indicate how you're communicating with
the database.  If you're using the DBI module, you may want to
consider using the 'quote' method for your data.

Also consider how you're getting the values in the first place. 
You're using a CGI script.  If the user should happen to put a bunch
of spaces into a text field, then the data you're working with will
have spaces (GIGO).  Are you taking this into account?  Are you even
validating what the user sends in the form?

HTH

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Jesus Saves, Moses Invests, But only Buddha pays Dividends. 



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

Date: Sun, 14 Sep 2003 13:36:46 -0700
From: Arvin Portlock <apollock11@hotmail.com>
Subject: Re: Maddening bug: Why do quotes fix it?
Message-Id: <bk2jh2$8e8$1@agate.berkeley.edu>

James Willmore wrote:

> On Sun, 14 Sep 2003 12:57:22 -0700
> Arvin Portlock  wrote:
>
> >So why does the simple fact of putting $category in quotes above
> >solve this bug?
>
> No where in your post do you indicate how you're communicating with
> the database.  If you're using the DBI module, you may want to
> consider using the 'quote' method for your data.

I'm using ADO via Win32::OLE. I didn't even know you could use ADO in
the DBI module! That would be very useful.



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

Date: Sun, 14 Sep 2003 20:49:06 GMT
From: James Willmore <jwillmore@cyberia.com>
Subject: Re: Maddening bug: Why do quotes fix it?
Message-Id: <20030914164912.4393b501.jwillmore@cyberia.com>

On Sun, 14 Sep 2003 13:36:46 -0700
Arvin Portlock <apollock11@hotmail.com> wrote:
<snip>
> I'm using ADO via Win32::OLE. I didn't even know you could use ADO
> in the DBI module! That would be very useful.

Yes, yes there is a DBD::ADO module for use with DBI.

Enjoy!

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
"Even the best of friends cannot attend each other's funeral."   
-- Kehlog Albran, "The Profit" 


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

Date: 14 Sep 2003 10:45:20 -0700
From: jamesb7us@yahoo.com (James Bonanno)
Subject: Newbie Help with Hashes
Message-Id: <3869c28a.0309140945.5948b5f6@posting.google.com>

Hello;

I've written a basic program that will scan a directory, and then
build a basic tree and turn that into HTML. The program is using the
File::Find::Rule and HTML::Template modules. I am building a basic
"project manager/reporting" software. I've arranged all my projects on
my computer in this strucutre:

Projects
--- Project1
----------Visio
----------Word
----------Schematics
----------Verilog
--- Project2
----------Visio
----------Word
----------Schematics
----------Verilog

 . . . and so on. What I really want to do is to be able to have
"irregular" numbers of subprojects under each project, and gracefully
handle them with my code. For example, if Project1 contained a
subdirectory "Excel" in addition to Visio,Word,Schematic, and Verilog,
I'd like the program to be able to handle that rather than having a
"fixed number" of subprojects. My code is shown below, where the my
%row hash is the problem. I want to be able to make proj1, proj2,
proj3 a "dynamic size". I'm a newbie at perl, please forgive my
approach if another is clearly more obvious. Any suggestions are
welcome.
Thanks,

James

use File::Find::Rule;
use HTML::Template;

$root = "C:/DATA_JAMES/Projects/";
@projects_to_display = &dirscan_root("$root");

# Build an array of project names
@projects = &dirscan("$root");

# Build a hash of multi-value keys associating
# each project with its various subprojects/subdirectories
foreach $dir ( @projects ) {
    $HoA{$dir} = [dirscan_root($dir)];
                 }

my $template = HTML::Template->new(filename => 'Find_Dir.html');
my @loop;  # the loop data will be put in here

# fill in the loop, sorted by directory name
  foreach my $name (sort keys %HoA) {
# get the directory and three proejcts from HoA hash
my ($dir, $proj1, $proj2, $proj3) = @{$HoA{$name}};
# make a new row for each project - the keys are <TMPL_VAR> names
# and the values are subprojects
my %row = (
          dir   => $name,
          proj1  => $proj1,
          proj2  => $proj2,
          proj3  => $proj3,
          );

    # put this row into the loop by reference
    push(@loop, \%row);
  }
$nowstring = localtime;
# call param to fill in the loop with the loop data by reference.
$template->param(project_loop => \@loop);
$template->param(path => $nowstring);
print "Content-Type: text/html\n\n";
# print the template
print $template->output;

    # This function scans the given directory and returns
    # every subdirectory
    sub dirscan_root{
    $dir_to_scan = shift(@_);
	@tree=File::Find::Rule->directory->relative->maxdepth(1)->in
("$dir_to_scan");
    shift(@tree);
	return (@tree);
    };

    # This function scans the given directory and returns
    # an array with subdirectories indicated with a full path
    sub dirscan{
    $dir_to_scan = shift(@_);
	@tree=File::Find::Rule->directory->maxdepth(1)->in("$dir_to_scan");
    shift(@tree);
	return (@tree);
    };


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

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


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