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

You still haven't answered where $error_excerpt comes from... but on second thought, maybe you meant (?)

sub error_excerpt{ my $self = shift; return defined($self->{_error_excerpt}) ? $self->{_error_excerpt} +: "No Error Excerpt."; }

Replies are listed 'Best First'.
Re^4: Question on XML output using Perl
by siddheshsawant (Sexton) on Mar 16, 2010 at 16:29 UTC

    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.

      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"; } }