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

Perhaps, as other monks have mentioned, something along these lines might point you in the right direction.
#!/usr/bin/perl use strict; use warnings; my $e = Error::Excerpt->new; print $e->get_error_excerpt, qq{\n}; $e->set_error_excerpt(q{We have an error}); print $e->get_error_excerpt, qq{\n}; package Error::Excerpt; sub new { my $class = shift; my $self = { _error_excerpt => undef, }; bless ($self, $class); return $self; } sub set_error_excerpt{ my $self = shift; my $ee = shift; $self->{_error_excerpt} = $ee; } sub get_error_excerpt{ my $self = shift; my $ee = $self->{_error_excerpt}; return $ee?$ee:q{No Error Excerpt}; }
No Error Excerpt We have an error
imo, dividing up the task using getters and setters is often worth considering. Add error checking as appropriate.

Replies are listed 'Best First'.
Re^4: Question on XML output using Perl
by siddheshsawant (Sexton) on Mar 16, 2010 at 16:30 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); r +eturn $self->{_error_excerpt};

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