Loading ...
Sorry, an error occurred while loading the content.

Re: Please help me parse this data structure.

Expand Messages
  • Damien Carbery
    Look up perldsc (Perl Data Structures Cookbook). It says you access an element in the array of hashes as: $AoH[0]{lead} = fred ; To access the whole thing: #
    Message 1 of 6 , Apr 3, 2001
    • 0 Attachment
      Look up perldsc (Perl Data Structures Cookbook).

      It says you access an element in the array of hashes as:
      $AoH[0]{lead} = "fred";

      To access the whole thing:
      # print the whole thing one at a time
      for $i ( 0 .. $#AoH ) {
      for $role ( keys %{ $AoH[$i] } ) {
      print "elt $i $role is $AoH[$i]{$role}\n";
      }
      }

      --- In perl-beginner@y..., Jhilmil Jain <jhilmilj@E...> wrote:
      >
      >
      > Hi,
      > I am learning Perl.
      > I need help to parse this data structure.
      >
      > My guess is that it is an array of hashes.
      > But I cant understand how to extract the key and values
      > of this data structure.
      >
      > Thanks,
      > Jhilmil
      >
      > $VAR1 = [
      >
      > { 'name' => 'foo',
      >
      > 'type' => 'e',
      >
      > 'content' => [
      >
      > { 'name' => 'head',
      >
      > 'type' => 'e',
      >
      > 'content' => [
      >
      > { 'type' => 't',
      >
      > 'content' => 'Hello '
      >
      > },
      >
      > { 'name' => 'em',
      >
      > 'type' => 'e',
      >
      > 'content' => [
      >
      > {
      'type' =>
      > 't',
      >
      >
      'content'
      > => 'there'
      >
      > }
      >
      > ],
      >
      > 'attrib' => {}
      >
      > }
      >
      > ],
      >
      > 'attrib' => { 'id' => 'a'
      >
      > }
      >
      > },
      >
      > { 'name' => 'bar',
      >
      > 'type' => 'e',
      >
      > 'content' => [
      >
      > { 'type' => 't',
      >
      > 'content' => 'Howdy'
      >
      > },
      >
      > { 'name' => 'ref',
      >
      > 'type' => 'e',
      >
      > 'content' => [],
      >
      > 'attrib' => {}
      >
      > }
      >
      > ],
      >
      > 'attrib' => {}
      >
      > },
      >
      > { 'type' => 't',
      >
      > 'content' => '
      >
      > do
      >
      > '
      >
      > }
      >
      > ],
      >
      > 'attrib' => {}
      >
      > }
      >
      > ];
    Your message has been successfully submitted and would be delivered to recipients shortly.