Hi monks, I am working in the validation of a file. I need to compare the attributes value present in the file with list of values.

I have stored the list of values for different attributes in "%attributes" hash. And I stored the attributes and their values in "%are" hash which are present in the file.

If the attribiute value which is present in the file, is not match with the list of values, then to raise error message.

Input is: <render fo:font-style="italic" fo:fontvariant="noormal">

Output is: (1) ERR :Line 19 Col 94
        Check the render attribute fo:fontvariant="noormal".

while ($file =~/<render([^>]*)>/gi) { my $atri=$1; $pre = $`; $ln= $pre =~s/\n/\n/g; ++$ln; ($pre=~/\n$/)?( $col=0):($col = length((split(/\n/,$p +re))[-1])); %attributes=('fo:font-style'=>["\"normal\"", "\"itali +c\"", "\"oblique\"", "\"backslant\"", "\"inherit\""], 'fo:fontvariant'=>["\"normal\"", "\"small-caps\"", "\ +"inherit\""], 'fo:fontweight'=>["\"normal\"", "\"bold\"", "\"bolder +\"", "\"lighter\"", "\"inherit\"", "\"100\"", "\"200\"", "\"300\"", " +\"400\"", "\"500\"", "\"600\"", "\"700\"", "\"800\"", "\"900\""], 'fo:visibility'=>["\"visible\"", "\"hidden\"", "\"col +lapse\"", "\"inherit\""]); @a= split(/ /,$atri); %are=map{split(/=/,$_)}@a; for (keys (%are)) { $k=$_; if ($k=~/(fo:font\-style|fo:fontvariant|fo:fontweight +|fo:visibility)/) { while($i != 14){ push(@app,$attributes{$_}->[$i]); $i++; } @abc=grep(/$are{$k}/, @app); print FOUT "\n\n(".++$Errno.") ERR :Line ".($ln)." Co +l ".(++$col)."\n\tCheck the render attribute $k=$are{$k}.\n" if ($abc +[0] eq ''); } } }

It works fine. But it is very lengthy proces. That is, pushing the list of values in the array, after that grepping the values etc.

Is there any easy method to do this?

Regards,
Velusamy R


In reply to 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.