in reply to Re: perl and xml
in thread perl and xml

I threw this together to encompass the whole system. Hopefully this provides enough information.
#!/usr/bin/perl -w use strict; use XML::Simple; use Data::Dumper; ### BEGINNING STRUCTURE my %t_type = ( 'a' => { one => {low => 1000, high => 3000, percent => 25}, two => {low => 200,high => 2000, percent => 30}, three => {low => 1000,high => 6000, percent => 40}, four => {low => 300,high => 1800, percent => 35}, five => {low => 10, high => 40, percent => 60}, six => {low => 2, high => 12, percent => 50}, seven => [ {select => 'small',low => 3,high => 3,percent => 30}, ], }, 'b' => { one => {low => 1000, high => 3000, percent => 25}, two => {low => 200,high => 2000, percent => 30}, three => {low => 1000,high => 6000, percent => 40}, four => {low => 300,high => 1800, percent => 35}, five => {low => 10, high => 40, percent => 60}, six => {low => 2, high => 12, percent => 50}, seven => [ {select => 'medium',low => 1,high => 1,percent => 10}, {select => 'large',low => 1,high => 1,percent => 10}, ], }, ); print "\t BEFORE\n"; print "data...\n"; print "$t_type{'b'}{'seven'}[0]->{'select'} \n"; foreach my $item ( @{$t_type{b}{seven}} ) { print "... $item->{'select'}\n"; } print "\n\t AFTER\n"; print "creating file...\n"; my $xsimple = XML::Simple->new(); open(L, ">tt.xml"); print L $xsimple->XMLout(\%t_type, noattr => 1, xmldecl => '<?xml version="1.0"?>', GroupTags => { 'seven' => 'select' } ); close(L); print "reading file...\n"; %t_type = (); my $t_type = XMLin('tt.xml',GroupTags => { 'seven' => 'select' }); %t_type = \$t_type;
%t_type = \$t_type;
How do I dereference back into the original structure? So I can access it the same way?
### lets test that returned structure # yep its the same. must be a referrence problem? print "dumping structure...\n"; print Dumper($t_type);
It appears to print the original hash except for the $VAR1 not being $t_type.
Then try to print it the same as before but doesn't work.
print "data...\n"; print "$t_type{'b'}{'seven'}[0]->{'select'} \n"; foreach my $item ( @{$t_type{b}{seven}} ) { print "... $item->{'select'}\n"; }
What do I need to do?

Replies are listed 'Best First'.
Re^3: perl and xml
by borisz (Canon) on Aug 29, 2004 at 18:01 UTC
    I think you just have to dereference t_type.
    ... my $t_type = XMLin('tt.xml',GroupTags => { 'seven' => 'select' }); %t_type = %$t_type;
    was that the question?
    Boris
      thanks boris that was it.