help... this perl is different... null values are crashing my script.

U

Uri Guttman

JS> $temp=$ENV{'QUERY_STRING'};
JS> @pairs=split(/&/,$temp);

use CGI.pm. it is portable and works. your code (of what little you
showed) is home brewed cgi and almost surely broken.

JS> The first line is not a problem, but if the QUERY_STRING
JS> environment is empty, the second line will crash.

and you use the term crash which has many meanings. your script is
broken, perl isn't.

JS> The above is just one example. The following will do the same:

JS> my $temp;
JS> if($temp==0){$a=1;}

JS> In both cases, the $temp scalar is empty (or null) and it causes
JS> my script to crash. I have never seen this happen before, and it
JS> is not happening in my other projects, only on this server. I can
JS> work around this so far, but it would make life so much simpler if
JS> it wouldn't be doing this.

there is no empty nor null value in perl. $temp is undefined. again you
say crash which is meaningless. the worst that will do is issue warnings
if warnings are enabled. you need to learn some basic perl before you go
blaming perl or the perl version.

uri
 
J

James Willmore

On Wed, 29 Oct 2003 02:58:50 GMT
John Smith said:
Today however, I was asked to write another perl script for another
project. This will be running on a different machine and
unfortunately, I don't have much info, I think it may be a on a sun
system? Anyway, after some debugging, I found that my script
crashes when I use a scalar that has a null value. For example:

If it's a *NIX box, use 'uname -a' to get information about the
machine :) And to see how Perl was compiled for the box (*NIX or
otherwise), type 'perl -V' at the command line :)
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);

The first line is not a problem, but if the QUERY_STRING environment
is empty, the second line will crash.

Use the CGI module. The module will prevent such wonderful things
like not splitting the params correctly - which _may_ be the reason
for the script failing.

Does anyone know how I could fix this?

Use the CGI module :)

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 ...
Things are more like they used to be than they are now.
 
E

Eric J. Roode

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I've been writing a little perl in the past few years, for web server
= CGI scripts to be more precise. Currently I am writing a script
which is = running on a Linux machine with Apache web server with Perl
5.6. This is = running great for me.

Today however, I was asked to write another perl script for another =
project. This will be running on a different machine and
unfortunately, = I don't have much info, I think it may be a on a sun
system? Anyway, = after some debugging, I found that my script
crashes when I use a scalar = that has a null value. For example:

$temp=3D$ENV{'QUERY_STRING'};
@pairs=3Dsplit(/&/,$temp);

The first line is not a problem, but if the QUERY_STRING environment
is = empty, the second line will crash.=20

In my script, this is used to read any parameters that were sent to
the = script from web browser URL, such as =
http://www.domain.com/cgi-bin/app.pl?year=3D2003. And it works if
there = are parameters, but if someone uses their web browser to
access = http://www.domain.com/cgi-bin/app.pl, there are no
parameters, the = QUERY_STRING environment is null, $temp is null and
crash! :(

The above is just one example. The following will do the same:

my $temp;
if($temp=3D=3D0){$a=3D1;}

In both cases, the $temp scalar is empty (or null) and it causes my =
script to crash. I have never seen this happen before, and it is not =
happening in my other projects, only on this server. I can work around
= this so far, but it would make life so much simpler if it wouldn't
be = doing this.

Does anyone know how I could fix this?

First and foremost, I would like to request a favor: Please do not post
MIME/multipart articles to usenet. Traditionally, you should post plain
text -- everyone expects that, and nobody (me, for example!) has to trim
out MIME stuff. TIA.

Second: What do you mean, exactly, by "crash"? In general, undefined
variables per se are harmless. If "use warnings" is in the script, they
will generate a warning -- not a fatal error. If "use warnings 'FATAL'"
is in the script, they will cause a fatal error; perhaps this is what you
mean by "crash".

Third: never EVER parse your own CGI input in production code. Always,
but ALWAYS use the excellent CGI.pm module. For example, even the two
simple lines you have posted above:
$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);

contain a bug. Possibly two, depending on what you count. Really.

- --
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN PGP SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP59HcGPeouIeTNHoEQIzXQCghgR6+ZaPPgxFK7+Dzme04KS0REYAn2lV
3WjJQyDYhTonkSuAQj2QJckR
=4dW6
-----END PGP SIGNATURE-----
 
S

Steven Smolinski

Tad McClellan said:
Oh. That explains why I'm seeing followups without having seen the OP.

Could you share your scorefile entry for this amazing feature? I've
tried to score on the Content-Type: multipart/alternative header, but
for some reason I cannot fathom it does not catch posts like this.

Steve
 
T

Tad McClellan

Steven Smolinski said:
Could you share your scorefile entry for this amazing feature? I've
tried to score on the Content-Type: multipart/alternative header, but
for some reason I cannot fathom it does not catch posts like this.


It's at the bottom of this section:

% foolish subjects
Score:: -9000
Subject: ^perl$
Subject: ^Re: \c[^a-z]*$
Subject: ^help!?$
Subject: ^question!?$
Subject: ^perl question!?$
Subject: (none)
Subject: no subject
Subject: ^$
Subject: !!!
Subject: ###
Subject: ~~~
Subject: \?\?\?
Content-Type: multipart/alternative
Content-Type: multipart/mixed
Content-Type: text/html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,141
Messages
2,570,817
Members
47,366
Latest member
IanCulpepp

Latest Threads

Top