Dubdubw has asked for the wisdom of the Perl Monks concerning the following question:

Here is probably an easy script question, and I appologize if it has already been addressed. What I have is a database that has a field name of Item, and a field name of Description. What I would like to do is print out the contents as follows:
Item \t Description \n.
When there is an exact duplication for the field Item, I would like the print to display the first occurance (Item \t Description \n) then (\t description \l) for each additional match of Item as follows:

Item \t Description \n.
\t Description \n. #Duplicate name from item above
\t Description \n. #Duplicate name from item above
Item \t Description \n.
Item \t Description \n.

TIA
Any help will be greatly appreciated. --Richard

Replies are listed 'Best First'.
Re: Duplicate DB Entries
by PodMaster (Abbot) on Jul 19, 2002 at 21:31 UTC
    So what is the problem?

    Build a nice HoA and then do the printing.

    On the other hand, you ought to quit dealing with flat files, please.

    Use a RDBMS like mysql, or something like DB_File

    Learn your perl data structures. Read perldata, perldsc, perllol and perlref

    $NiceHash{ItemC} = [ Desc => Desc1 => Desc2 => 3 ];
    ____________________________________________________
    ** The Third rule of perl club is a statement of fact: pod is sexy.
Re: Duplicate DB Entries
by Aristotle (Chancellor) on Jul 19, 2002 at 22:01 UTC
    #!/usr/bin/perl -w use strict; my (%desc, $item, $desc); chomp $desc, push @{$desc{$item}}, $desc while ($item,$desc) = split /\t/, scalar <>, 2; # output differs from the format you described, but I don't # believe the \n's make sense where you asked for them print "$item\t$desc->[0]\n", map "\t$desc->[$_] #Duplicate name from i +tem above\n", 1..$#$desc while ($item,$desc) = each %desc;
    ____________
    Makeshifts last the longest.