Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re^2: Parsing Data Help!

by Anonymous Monk
on Mar 15, 2013 at 15:13 UTC ( #1023717=note: print w/replies, xml ) Need Help??

in reply to Re: Parsing Data Help!
in thread Parsing Data Help!

The issue is how to interact with this structure, trying but getting an error with:
for my $items( @{$p} ){ print $item->{account} . "\n"; print $item->{ZIP} . "\n"; print $item->{CITY} . "\n"; print $item->{order} . "\n"; print $item->{suggested} . "\n"; print $item->{cd} . "\n"; };

Replies are listed 'Best First'.
Re^3: Parsing Data Help!
by choroba (Bishop) on Mar 15, 2013 at 15:23 UTC
    The structure is not flat. You have to follow it deeper if needed:
    for my $item (@{$p}) { if ('HASH' eq ref $item) { for my $key (qw(account ZIP CITY)) { print $item->{$key} , "\n" if exists $item->{$key}; } } elsif ('ARRAY' eq ref $item) { for my $inner (@$item) { for my $key (qw(order suggested cd)) { print "\t", $inner->{$key} , "\n" if exists $inner->{$ +key}; } } } }
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re^3: Parsing Data Help!
by hdb (Monsignor) on Mar 15, 2013 at 15:20 UTC
    Here is one way:
    sub findcd { my $someref = shift; my $type = ref($someref); if( $type eq "" ) { # do nothing for non-references } elsif( $type eq "ARRAY" ) { foreach my $elem (@{$someref}) { findcd( $elem ); } } elsif ($type eq "HASH" ) { foreach my $elem (keys %{$someref}) { print "cd: $$someref{$elem}\n" if $elem eq "cd"; findcd( $$someref{$elem} ); } } else { warn "Cannot deal with $type.\n"; } } findcd( $p );
    but I am sure there is a module doing it simpler.
    For every complex problem there is an answer that is clear, simple, and wrong. H. L. Mencken
      You are right, its not flat,I need a module to do this or flat the data somehow.
Re^3: Parsing Data Help!
by Anonymous Monk on Mar 15, 2013 at 15:21 UTC

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023717]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2018-01-23 11:54 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (244 votes). Check out past polls.