#!/usr/bin/perl use strict; use warnings; use Data::Dumper; open FILE ,"temp" or die("can not open temp $!"); my $line ; my (%resultarray,$part1,$part2); my @AoH=(); while($line = <FILE>) { chomp($line); ($part1,$part2) = split(/#/,$line); my @resultarry2=split(/\s/,$part1); %resultarray=split(/[=;]/, $part2); my $datetime="$resultarry2[1] $resultarry2[2]"; my $threadname=$resultarry2[6]; $resultarray{"datetime"}=$datetime; $resultarray{"threadname"}=$threadname; push @AoH, \%resultarray; } close(FILE); my $numberofhashes=scalar(@AoH); print $numberofhashes."\n"; my $hr2=\@AoH; print Dumper $hr2;
Output is
4
$VAR1 = [
          {
            'threadname' => '241e2260-a74f-4122-af42-9def1fa0318c',
            'eventType' => 'REQUESTUPDATE',
            'objectType' => 'VE',
            'objectId' => '1447553 ',
            'requestType' => 'CREA',
            ' requestId' => '874',
            'datetime' => '2011-08-12 10:05:19,250'
          },
          $VAR1->[0],
          $VAR1->[0],
          $VAR1->[0]
        ];
--------------------
I'm expecting 4 Hashes inside the array. Please, let me know what mistake am doing ?

In reply to problem in Pushing to Array of hash by perl_peter

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.