From the looks of things, you're attempting to validate CSS. You might want to search on your favorite search engine for 'CSS validator', so you don't have to duplicate work.

As for testing if an item is in a list ... when the list doesn't change, as in your case, you can build a hash with a list as its keys (preferably, outside the loop, or at whatever level it doesn't change), and then just test if the item is a key in the hash.

# before the loop sub enquote { return { map { qq("$_") => undef } @_ }; } my %attributes=( 'fo:font-style' => enquote( qw(normal italic oblique backslant inher +it ) ), 'fo:fontvariant'=> enquote( qw(normal small-caps inherit ) ), 'fo:fontweight' => enquote( qw(normal bold bolder lighter inherit 10 +0 200 300 400 500 600 700 800 900) ), 'fo:visibility' => enquote( qw(visible hidden collapse inherit) ), ); # then, when you're inside the loop: for my $k (keys (%are)) { if ( exists( $attributes{$k} ) ) { if ( ! exists($attributes{$k}{$are{$k}}) ) { print FOUT $errorMessage; } } }

I would also suggest that you select an indenting style, and then stick to it -- it took me longer to understand the logic that you were trying, than to write a response. (better selection of variable names would have been useful, as well)

If the script isn't going to be long running, and/or you're not expecting a whole lot of items that aren't going to be in the test list, you can just set the hash values to a 'true' value, and you can leave out the calls to 'exists':

sub enquote { return { map { qq("$_") => 1 } @_ }; } my %attributes=( 'fo:font-style' => enquote( qw(normal italic oblique backslant inher +it ) ), 'fo:fontvariant'=> enquote( qw(normal small-caps inherit ) ), 'fo:fontweight' => enquote( qw(normal bold bolder lighter inherit 10 +0 200 300 400 500 600 700 800 900) ), 'fo:visibility' => enquote( qw(visible hidden collapse inherit) ), ); ##### for my $k (keys (%are)) { if ( $attributes{$k} and ! $attributes{$k}{$are{$k}} ) { print FOUT $errorMessage; } }

In reply to Re: How to compare two hashes by jhourcle
in thread How to compare two hashes by Samy_rio

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.