Okay, I'm playing around with this just for funz and learninz and I've hit something I'm having trouble explaining: Why does evalnot detect this as an error?
Original command placed in script and executed:
#!/usr/bin/perl use strict; use warnings; print qq{perl version: $] \n};;; my $x; my %y= ("h"=>1, "i"=>2); print $x, $y{x}; printf "%s", $x; exit; __END__
Produces, as advertised:
U:\>uninit01.pl perl version: 5.018002 Use of uninitialized value $x in print at U:\uninit01.pl line 10. Use of uninitialized value in print at U:\uninit01.pl line 10. Use of uninitialized value $x in printf at U:\uninit01.pl line 11.
So I tried to capture the error in an evalblock:
#!/usr/bin/perl use strict; use warnings; print qq{perl version: $] \n};;; my $x; my %y= ("h"=>1, "i"=>2); eval { print $x, $y{x}; } ; # Check for error out of eval{} if ($@) { # There was an error trapped. my $dsperr = $@; print "-------------------------\n"; print "$dsperr\n"; print "-------------------------\n"; } else { print "No error found.\n"; } printf "%s", $x; exit; __END__
But this produced:
U:\>uninit02.pl perl version: 5.018002 Use of uninitialized value $x in print at U:\uninit02.pl line 12. Use of uninitialized value in print at U:\uninit02.pl line 12. No error found. Use of uninitialized value $x in printf at U:\uninit02.pl line 29.
What is it about evalthat I'm not understanding properly here?
In reply to Re: determine the variable causing the error: Use of uninitialized value
by marinersk
in thread determine the variable causing the error: Use of uninitialized value
by ruqui
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |