Subject: | uninitialized value |
I have installed "Switch-2.07" module in perl v5.6.0 built for sun4-solaris: SunOS 5.7 Generic_106541-17 sun4u sparc SUNW,Ultra-5_10.
It works OK and I like it very much - great job, thanks a lot! However, there is an issue, which I'd like to address.
The original Switch.pm module gives me warning about uninitialized
variable $arg in line 124 and prints "[]", like this:
Use of uninitialized value in concatenation (.) at Switch.pm line 124.
[]
val == 1
hello
And this is code used for testing of original Switch.pm :
#!/usr/local/bin/perl -W
use lib qw(.);
use Switch;
my $val = 1;
switch ($val) {
case 10 { print("val == 10 \n") }
case 1 { print("val == 1 \n") }
else { print("val is else \n") }
}
print("hello \n");
For some reason $4 arg is empty, thus $arg is empty too. In my version of Switch.pm, I have fixed this, by checking if $arg is defined before printing (line 125). Hopefully, it's a right thing to do, but I'd like your opinion on that, because I am not sure why I am hitting this line of code anyway.
Please find fixed Switch.pm module attached. My code now prints without warnings :
val == 1
hello
Message body is not shown because it is too large.