On 2010-10-01 04:37, Jon Hermansen wrote:

sub is_valid_xml {
     my ($content) = @_;

     eval {
         my $xs = XML::Simple->new();
         my $ref = $xs->parse_string($content);
     };

     return 1 unless ($@);
}

Don't test the truth of $@, but use the return value of the eval.


     my $result;

     eval {
         $result = process();
         ...
         1;  # success
     }
     or do {
         my $eval_error = $@ || "unknown";
         ...
     };  # needs a semicolon

--
Ruud

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to