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

Re: printing hashes of arrays

Expand Messages
  • Damien Carbery
    ... perldoc perldsc Data Structures Cookbook It describes how to create hashes of hashes and then how to access and print them. It also does other combinations
    Message 1 of 4 , Jan 4, 2007
      --- In perl-beginner@yahoogroups.com, Noah <admin2@...> wrote:
      >
      > Hi there list,
      >
      > I am having a little difficulty understanding how to print all the
      > elements of arrays that are encompassed in a hash.
      >
      perldoc perldsc
      Data Structures Cookbook
      It describes how to create hashes of hashes and then how to access and
      print them. It also does other combinations of arrays and hashes.

      http://aspn.activestate.com/ASPN/docs/ActivePerl/5.8/lib/Pod/perldsc.html#hashes_of_hashes
    • a_z0_9_blah
      ... sub ... {LOCAL_IP} } . ... scalar @{ ... for ... [snip] ... This is one way to give you all records. printf %s is hostname {LOCAL_IP} } n ,
      Message 2 of 4 , Jan 5, 2007
        --- In perl-beginner@yahoogroups.com, Noah <admin2@...> wrote:
        >
        > Hi there list,
        >
        > I am having a little difficulty understanding how to print all the
        > elements of arrays that are encompassed in a hash.
        >
        > I am reading a CSV file into a hash of hashes styled record in the
        sub
        > read_datafile, and the printing is done in the sub called
        > print_all_records. In print_all_records I am having difficulty
        > printing the output of all the elements of "@{ $record->
        {LOCAL_IP} }".
        > it appears that only the first element prints. The variable
        scalar @{
        > $record->{LOCAL_IP} } clearly shows there are more than 1 element
        for
        > some of the arrays.
        >
        > Below are the subroutines,


        [snip]

        >
        > ----- sub print_all_records ------
        >
        > sub print_all_records
        > {
        > while (($hostname, $record) = each %byhostname)
        > {
        > printf "%s is hostname <<%s>>\n", $hostname, @{
        > $record->{LOCAL_IP} };


        This is one way to give you all records.


        printf "%s is hostname <<@{$record->{LOCAL_IP} }>>\n", $hostname;




        > printf "%s is hostname <<%s>>\n", $hostname, scalar @{
        > $record->{LOCAL_IP}\
        > };
        > }
        > }

        Chris
      Your message has been successfully submitted and would be delivered to recipients shortly.