my @report; while (my $line = <$log_file>) { my @fields = (split / /, $line); $report[$_]{$fields[$_]}++ for 2,4,5,9,7,1; }

should do! (untested)

But I would rather use names for each column in a HoH (since you are skipping indices), so

   $report{ $column[$_] }{ $fields[$_] }++  for 2,4,5,9,7,1;

might be better! (for a hash my %report of course)

Cheers Rolf

( addicted to the Perl Programming Language)

UPDATE

using column-numbers as names/keys in a HoH

use strict; use warnings; use Data::Dump qw/dd/; my %report; while (my $line = <DATA>) { next if $line =~ /^\s*$/; # skip empty lines my @fields = (split / /, $line); $report{$_}{$fields[$_]}++ for 2,4,5,9,7,1; } dd \%report; __DATA__ 483 OS dx-32 1 charles list4 aardvark.com ty-off lx-on C 01 483 DS dx-14 1 james list3 23.456.12.7 ty-on lx-on B 01 769 XO dx-32 5 sully nolist widgets.com ty-on lx-on V 07

thats what you want?

{ 1 => { DS => 1, OS => 1, XO => 1 }, 2 => { "dx-14" => 1, "dx-32" => 2 }, 4 => { charles => 1, james => 1, sully => 1 }, 5 => { list3 => 1, list4 => 1, nolist => 1 }, 7 => { "ty-off" => 1, "ty-on" => 2 }, 9 => { B => 1, C => 1, V => 1 }, }

In reply to Re: array of hashes, categorized by array index by LanX
in thread array of hashes, categorized by array index by tevus_oriley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.