This is in regards to my question concerning looping on a growing hash. For more background on this refer to How do I...? - Looping on a growing hash.

First...thanx to kanji and jeffa for their help on the LOOP trigger.

Some background
=============================

I have a hash called %links that is structured in the following manner:

%links{URL_NAME}{count}     # of occurances (this URL)
                {depth}     Number of pages from root doc
                {title}     text in TITLE tag
                {text}      HTML-stripped contents of page
                {visited}   flag to indicate traversal

The URL_NAME key will be the absolute URL (http://www.someserver.com/somedir/somepage.html) to the page in question. This %links hash will contain a list of URLs that I want to visit in order to build a data file from the resulting traversal with the data in the completed %links hash.

What I'm attempting to do
=============================

I am looking for the best way to retrieve a entry from the hash that has {visited} UNDEFined (or maybe even set to 0...must likely UNDEFined). The current suggestions are to do something along the lines of:

my @keys = grep ! defined $links{$_}->{'visi ted'}, keys %links;

However, this code recreates the array with every value in the hash that matches the condition which is more than I want. Besides, the hash could contain hundreds of entries and this just adds to the processing overhead.

To keep processing fast and extranous information at a minimum, I only need 1 URL_NAME to be returned at a time. The returning order is unimportant as the loop will process all the entries anyways.

Is it possible to return just 1 entry and reduce total processing cycles? If so, how?

A better question might be: Am I really speeding things up by getting 1 entry....will the REGEX process the entire hash before returning 1 entry anyways? Is processing an issue on an array that contains X number of entries that gets recreated X - 1 times each pass?

As always...pro/con input graciously accepted.

======================
Sean Shrum
http://www.shrum.net


In reply to Returning 1 entry from a conditional grep call to a hash value by S_Shrum

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.