Problems I see in your code:

Here is my re-write of your core code, using HoA grouping and hash slices. Working, tested code:

#!/usr/bin/perl -W use strict; use warnings 'all'; use Data::Dumper; $Data::Dumper::Useqq = 1; $| = 1; my @field_names = qw( PROP COLOUR TXTCOL URL360 USER YOUR_NAME ADDRESS TOWN ZIP_CODE COUNTRY EMAIL TELEPHONE_NO TELEPHONE_NO2 THEME WEB_ADDRESS PPEMAIL JUNK1 JUNK2 JUNK3 ); # Simplified @field_names for this example: @field_names = qw( PROP COLOUR USER YOUR_NAME ); # 'Prop' is a unique key in file PAGE and in hash %onprop. my %onprop; # HoH # 'user' is not unique, so each hash entry will be an array of 'Prop's +. my %user_props; # HoA while (<DATA>) { chomp; next unless /\S/; my @fields = split "\t"; warn unless @fields == @field_names; my %h; @h{@field_names} = @fields; my $prop = $h{PROP} or warn; my $user = $h{USER} or warn; # Create array of users and hash of data warn "Overwriting '$prop'" if exists $onprop{$prop}; $onprop{$prop} = \%h; push @{ $user_props{$user} }, $prop; } print Data::Dumper->Dump( [ \%onprop, \%user_props ], [ qw( *onprop *user_props ) ], ); print join("\t", @field_names), "\n\n"; foreach my $user ( sort keys %user_props ) { my @prop_list = @{ $user_props{$user} }; my $number_of_props = @prop_list; print "Grouped data ($number_of_props lines) for user '$user'\n"; foreach my $prop (@prop_list) { my %h = %{ $onprop{$prop} }; my @fields = @h{@field_names}; print join("\t", @fields), "\n"; } print "\n"; } __DATA__ foo red jonnyfolk Saint J bar white Util Me baz blue jonnyfolk Saint J qux black Util Me2


In reply to Re: grouping lines of data together for later use by Util
in thread grouping lines of data together for later use by jonnyfolk

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.