Samy_rio has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to compare two hashes
by jhourcle (Prior) on Jul 09, 2005 at 13:54 UTC | |
by Samy_rio (Vicar) on Jul 11, 2005 at 04:00 UTC | |
|
Re: How to compare two hashes
by friedo (Prior) on Jul 09, 2005 at 12:04 UTC | |
by Samy_rio (Vicar) on Jul 09, 2005 at 12:13 UTC |