2010/1/16 Grant <emailgr...@gmail.com>: >>> <LabelResponse> >>>> <Label> >>>> <Image Number="1">base64datahere</Image> >>>> <Image Number="2">base64datahere</Image> >>>> <Image Number="3">base64datahere</Image> >>>> </Label> >>>> </LabelResponse> >>>>
>> #!/usr/bin/perl >> >> use strict; >> use warnings; >> use XML::Simple; >> >> my $data = XMLin($path_to_file); >> >> foreach my $image (@{$data->{Label}->{Image}}) { >> print "$image->{content}\n"; >> } > Thanks Erez, I will stick with XML::Simple for now. I need to save > each set of base64data to a separate variable, so I can save each to a > separate file. How can I save each to a separate variable? if you need to save the content to a file, you can already do that inside the loop, using, in the example above the "$image->{content}" as the files content. You'd need to generate different file names, Similar to: foreach my $image (@{$data->{Label}->{Image}}) { my $filename = "image".$image->{Number}; #value of "Number" attribute open my $FH, '>', $filename or die $!; flock $FH, LOCK_EX or die $!; print $FH $image->{content} or die $!; close FH or die $!; } BTW, to actually understand what does XML::Simple do with the XML it gets, it is most recommended to add use Data::Dumper; print Dumper($data); before you try anything with the actual parsed Data-structures. -- Erez "The government forgets that George Orwell's 1984 was a warning, and not a blueprint" http://www.nonviolent-conflict.org/ -- http://www.whyweprotest.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/