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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.