in reply to Re^3: Question on XML output using Perl
in thread Question on XML output using Perl

If I keep a code like this then I gets error_escrpt where ever it is defined ....I am getting the value from the database...the code is as follows:

$self->{_error_excerpt} = $error_excerpt if defined($error_excerpt); return $self->{_error_excerpt};

But the problem with this code is it do not print anything when there is no error excerpt.

Replies are listed 'Best First'.
Re^5: Question on XML output using Perl
by Khen1950fx (Canon) on Mar 16, 2010 at 16:34 UTC
    If there is no error excerpt:
    #!/usr/bin/perl use strict; use warnings; use XML::Simple qw(:strict); sub new { my ($class) = @_; #my ($proto) = @_; #to make the constructor both class and object method #my $class = ref($proto) || $proto; my $self = { #attributes of object _id => undef, _user_scenario => undef, _result_type => undef, _result_log_link => undef, _not_exposed_reason => undef, _error_excerpt => undef, _triage => undef, }; bless $self, $class; return $self; } sub error_excerpt { } if ( defined('_error_excerpt') ) { print "error Excerpt\n"; } else { if ( not defined('_error_excerpt') ) { print "No error Excerpt exists\n"; } }