"sometimes ‘x’ has a value and so $cVar gets a value, other times no value
"
Do you mean that 'x' is undefined in both cases, or that 'x' has or may
have the value of an empty string, or have you not checked this?
Potentially, the two programmes are being sent different types of
'non-value'.
This is significant - compare the output of:
perl -we "print substr('',0,1);"
(empty string, all fine)
perl -we "print substr(undef,0,1);"
(undefined value generates a warning)
perl -e "print substr(undef,0,1);"
(warnings is not switched on so undefined value warning doesn't show up)
So consider something like:
my $param_x = CGI::param('x');
$param_x = '' unless defined $param_x;
my $cVar = substr($param_x,0,1);
Then make sure warnings are on in both scripts.
Daniel
From: "John DePasquale" <[email protected]>
To: <[email protected]>
Date: 26/09/2011 06:33
Subject: fickle warning
Sent by: [email protected]
Hi all,
I have what I’m sure is the simplest but nonetheless most vexing problem,
I just can’t figure what’s wrong.
I have two perl programs, both web applications. The same line appears in
both, which is:
my $cVar = substr( CGI::param( 'x' ), 0, 1 );
sometimes ‘x’ has a value and so $cVar gets a value, other times no value.
In the first program, a non-value for x is a non-event and everything is
fine.
But in the other program, when there’s a non-value for x I get the error
“Use of uninitialized value in substr at . . . “. This error message shows
up in my html output so the user sees the error message. I don’t
understand why the error is being sent in the html stream to the browser
from one program and not the other. Any guidance is greatly appreciated.
Thanks.
- john
John DePasquale
Chief Executive Officer
Paradigm Consulting
49 Dalby Street
Newton, MA 02458
Mobile: 617-610-2424
Fax: 617-600-7326
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs