in reply to Re: The error says the value is uninitialized, but it works anyway
in thread The error says the value is uninitialized, but it works anyway
Of course this left me with a lot of questions originally. Here is what prints for me.use warnings; my @colors = qw(red green blue yellow pink purple brown); my $count = @colors; my @drop = qw(pink brown); my $num = 0; foreach $num (1..$count){ $num--; print "$count \n"; print "$num \n"; print "$colors[$num] \n"; if ($colors[$num] eq $drop[0] or $colors[$num] eq $drop[1]){ splice (@colors, $num, 1); } else { print "$colors[$num] was not dropped from the array \n"; } } print "@colors \n";
I understand now, that the element "purple" is never evaluated, its skipped when "pink" is removed and the element numbers change. Then the next element "brown" is removed and then there are basically 2 empty spaces that the loop is trying to evaluate.7 0 red red was not dropped from the array 7 1 green green was not dropped from the array 7 2 blue blue was not dropped from the array 7 3 yellow yellow was not dropped from the array 7 4 pink 7 5 brown 7 6 Use of uninitialized value within @colors in concatenation (.) or stri +ng at C:\Users\..ch7q4.pl line 10. Use of uninitialized value in string eq at C:\Users\..ch7q4.pl line 11 +. Use of uninitialized value in string eq at C:\Users\..ch7q4.pl line 11 +. Use of uninitialized value within @colors in concatenation (.) or stri +ng at C:\Users\..ch7q4.pl line 15. was not dropped from the array red green blue yellow purple
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: The error says the value is uninitialized, but it works anyway
by BillKSmith (Monsignor) on Aug 19, 2019 at 15:23 UTC |