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

/me grovels and presents my humble question

As i'm reading in an HTML file, I would like say something like this:

if( $_ =~ /<span class="$hash{$ANY-KEYS-IN-THE-HASH}"/i .. /span>/i ) +{ print $_; }

but, i can't seem to make the interperter happy with any of they ways i've been saying $ANY-KEYS-IN-THE-HASH. i think (know) a loop or nested if statments might be a bit klunky.

any suggestions or ideas?
thanks!

Replies are listed 'Best First'.
Re: Reg-Ex, range, and Exists...
by Tomte (Priest) on Mar 12, 2003 at 15:57 UTC

    Maybe something like

    if (m/<span class="([^"]+)"/i && defined($hash{$1}) { print; }
    this is untested, though

    regards,
    tomte


    Update: I guess BrowserUK is right, so please reread the post with s/defined/exists/ :-)

      Maybe exists would be better than defined in this instance?


      Examine what is said, not who speaks.
      1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
      2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
      3) Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke.
      For me it seems that he rather want the expression to match when there is a value from the hash in the line rather than a key.
Re: Reg-Ex, range, and Exists...
by zby (Vicar) on Mar 12, 2003 at 16:20 UTC
    You could make a string containing joined list of the values from the hash like this: $altrenative = join '|', values %hash. And then use it in the regexp in place of $hash{$ANY-KEYS-IN-THE-HASH}.

    Update: The answers above me make the expression match when in the line there is a key from the hash, mine matches when there is some value from the hash. From the question I cannot say which one is correct.

      you've all given me much to think on.
      thanks!!

      - dhj
      -----------------------------
      I'm Immortal. So far, anyway.

Re: Reg-Ex, range, and Exists...
by boo_radley (Parson) on Mar 12, 2003 at 16:00 UTC
    If I'm reading your question correctly, you can grep against the keys of the hash.