Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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"; };


Comment on Re^2: Parsing Data Help!
Download Code
Re^3: Parsing Data Help!
by hdb (Prior) 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
Re^3: Parsing Data Help!
by choroba (Canon) 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}; } } } }
    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2015-07-03 17:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (55 votes), past polls