You might find module Graph helpful for some of what you are doing.

Some of your questions/difficulties relate to quite basic aspects of Perl and data structures. This is not surprising given you say you are a "newbie". As in the addage "you must learn to walk before you can run", it may be quicker for you to put aside your bigger problem briefly and focus on the basics. A good place to start for Perl, with links to many resources is: Where and how to start learning Perl. Otherwise, you might make sure you are familiar with data structures, graphs, algorithms in general, statistics and sets. Once you know all this (and I am not trying to suggest you currently know none of it) you will be able to solve your bigger problem much more easily and more quickly.

In particular, it seems you need to review: perldata, perlreftut, perlref, perldsc and perllol. These will help you better understand several of your problems and make you aware of alternative solutions for them.

update:

Again, the problem of excluding something if it already exists.

A common technique for finding/avoiding duplicates is to use a hash to store what you already have and then do lookup.

#!/usr/bin/perl # use strict; use warnings; my @list_of_items = qw(a b c a d b b z f); my %seen; foreach my $item (@list_of_items) { if($seen{$item}++) { # do what is appropriate for items that have already been seen print "saw an $item again\n"; } else { # do what is appropriate for items that have not already been +seen print "saw an $item\n"; } } foreach my $item (sort keys %seen) { print "$item is in \@list_of_items $seen{$item} " . (($seen{$item} + > 1)?"times\n":"time\n"); }

In reply to Re^5: Tallying appearance of a unique string from hash keys by ig
in thread Tallying appearance of a unique string from hash keys by jack_j

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.