CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
suppressing an uninitialized value

 



naphstor
Novice

Oct 13, 2009, 11:41 PM

Post #1 of 4 (288 views)
suppressing an uninitialized value Can't Post

hi i have a script which reads data from a xml file and then prints that data in another html file. now i m facing a issue that some of the entries in data (entries shown in color below) in xml file is uninitialized (shown in red color), so when i am printing the values in html file, there is some kind of bizarre string (something like "HASH(0x1b405dc)") is coming in html file for the uninitialized entries. what i did is to put a condition and check for the empty string, but still its not working.


Code
   <RELEASE_REQUEST_TRACK> 
<CODEC_NAME>WMV9SP_DEC</CODEC_NAME>
<PLATFORM>DM6446</PLATFORM>
<REL_REQ_ID>9</REL_REQ_ID>
<REL_VERSION>2.3.dummy</REL_VERSION>
<REQUESTED_BY>100161 </REQUESTED_BY>
<STATUS>Received</STATUS>
</RELEASE_REQUEST_TRACK> <RELEASE_REQUEST_TRACK>
<CODEC_NAME>MPEG4ASP_ENC</CODEC_NAME>
<PLATFORM>DM6446</PLATFORM>
<REL_REQ_ID>10</REL_REQ_ID>
<REL_VERSION></REL_VERSION>
<REQUESTED_BY>IN0027 </REQUESTED_BY>
<STATUS>Received</STATUS>
</RELEASE_REQUEST_TRACK>



i am trying to print the values of REL_VERSION in html file. Since the blue color string contains value so it is fine, but the red color is uninitialized so it is showing some hash string. so how to avoid this occurence of hash string.


shawnhcorey
Enthusiast


Oct 14, 2009, 5:41 AM

Post #2 of 4 (281 views)
Re: [naphstor] suppressing an uninitialized value [In reply to] Can't Post

What module are you using to parse the XML?

__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".


naphstor
Novice

Oct 14, 2009, 9:55 PM

Post #3 of 4 (275 views)
Re: [shawnhcorey] suppressing an uninitialized value [In reply to] Can't Post


Code
use XML::Simple;



i am working with xml files using perl first time. so i dont know if there is any way. i saw something about suppressing of uninitialized values, but dont know how to use it.


shawnhcorey
Enthusiast


Oct 15, 2009, 6:00 AM

Post #4 of 4 (260 views)
Re: [naphstor] suppressing an uninitialized value [In reply to] Can't Post

XML::Simple does not distinguish between attributes and content. It packs everything into a hash of hashes of hashes ..., to the depth needed. The string "HASH(0x1b405dc)" is what you get when you print a hash reference. Try testing for a reference to an empty hash.

Code
use Data::Dumper; 

# Make Data::Dumper pretty
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;

# Set maximum depth for Data::Dumper, zero means unlimited
$Data::Dumper::Maxdepth = 0;

if( ref( $thingy ) ){
if( ref( $thingy ) eq 'HASH' ){
if( 0 == keys %$thingy ){
# empty hash, don't print
}else{
# non-empty hash
print Dumper $thingy;
}
}else{
# reference not a hash, shouldn't happen
die "unknown reference: ".ref($thingy)."\n";
}
}else{
print "$thingy\n";
}


__END__

I love Perl; it's the only language where you can bless your thingy.

Perl documentation is available at perldoc.perl.org. The list of standard modules and pragmatics is available in perlmodlib.

Get Markup Help. Please note the markup tag of "code".

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives