dishantarora has asked for the wisdom of the Perl Monks concerning the following question:
I am getting following error every time I code in perl. Don't know hwy this is coming and what I am missing. I have placed small code sample below. This code is also giving me same error. As far as I get I am doing mistakes in traversing arrays
Error: Use of uninitialized value in print at printArrayWithOutLoop.pl line 20 (#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. To help you figure out what was undefined, perl will try to tell you the name of the variable (if any) that was undefined. In some cases it cannot do this, so it also tells you what operation you used the undefined value in. Note, however, that perl optimizes your program and the operation displayed in the warning may not necessarily appear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program.
This code will print each number in integer array in new line without using for or while loop.
Thanks all for finding error and teaching those things.use strict; use warnings; use diagnostics; use 5.010; my @inputArray = (1,2,3,4,5,6,7,8); my $inputArrayLen = @inputArray; my $counter = 0; &traverseArray($inputArrayLen); sub traverseArray{ if($counter<=$inputArrayLen){ print $inputArray[$counter]; print "\n"; $counter++; traverseArray($inputArrayLen); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Use of uninitialized value in print at line 20 (#1)
by davido (Cardinal) on Feb 25, 2016 at 06:12 UTC | |
by dishantarora (Initiate) on Mar 03, 2016 at 09:00 UTC | |
|
Re: Use of uninitialized value in print at line 20 (#1)
by GrandFather (Saint) on Feb 25, 2016 at 06:21 UTC | |
|
Re: Use of uninitialized value in print at line 20 (#1)
by Laurent_R (Canon) on Feb 25, 2016 at 10:12 UTC | |
|
Re: Use of uninitialized value in print at line 20 (#1)
by AnomalousMonk (Archbishop) on Feb 25, 2016 at 16:23 UTC |