Home > Archive > PERL Beginners > December 2007 > Use of uninitialized value in numeric ne error
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Use of uninitialized value in numeric ne error
|
|
| Lerameur 2007-12-21, 7:02 pm |
| Hello and cheers to all,
I wrote a small program and it does work, but I get this error message
every tim I run the script:
Use of uninitialized value in numeric ne (!=) at ./reverse_string.pl
line 11.
basically it is a menu and when the user type 99 as a choice, the
program ends
line 11 is:
while ( $line != 99){
thanks
ken
| |
| Yitzle 2007-12-21, 7:02 pm |
| I'd guess $line is never set before the first time it is compared to 99.
Either (1) change line 11 to:
$line = 0;
while ( $line != 99){
or (2) use a do-while loop.
do {
...
} while ( $line != 99);
| |
| Dan Klose 2007-12-21, 7:02 pm |
| On 21 Dec 2007, at 10:43, lerameur wrote:
> Hello and cheers to all,
hello
>
> I wrote a small program and it does work, but I get this error message
> every tim I run the script:
> Use of uninitialized value in numeric ne (!=) at ./reverse_string.pl
> line 11.
> basically it is a menu and when the user type 99 as a choice, the
> program ends
>
if like is a string the you can't do != as it is a numerical comparison
> line 11 is:
> while ( $line != 99){
more of the script would be handy - as it looks (at a quick glance)
as if $line is null.
>
> thanks
> ken
Dan.
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
| |
| Patmarbidon 2007-12-22, 4:01 am |
| What is the origin of $line ?
if you wrote $line = <STDIN> you should remove the "\n" and or "\r\n" at
the end of $line.
And if the user enter not numeric value you should always shuch an error.
You should check if the value is numeric or use 'eq' instead of '!=' .
If you removed the "\n" ou "\r\n"
while ( $line eq "99" ){
or
while ( $line eq "99\n" ){
or under win32
while ( $line eq "99\r\n" ){
lerameur a écrit :
> Hello and cheers to all,
>
> I wrote a small program and it does work, but I get this error message
> every tim I run the script:
> Use of uninitialized value in numeric ne (!=) at ./reverse_string.pl
> line 11.
> basically it is a menu and when the user type 99 as a choice, the
> program ends
>
> line 11 is:
> while ( $line != 99){
>
> thanks
> ken
>
>
| |
| Yitzle 2007-12-22, 7:02 pm |
| On 12/22/07, patmarbidon <patmarbidon@free.fr> wrote:
> or under win32
> while ( $line eq "99\r\n" ){
I /think/, under Perl, "\n" is the system newline, regardless of the OS.
Under Windows, it would still be "99\n"
|
|
|
|
|