Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Need advice (module) to parse nested IF/ELSIF..by l3nz (Friar) |
on Jan 28, 2004 at 18:05 UTC ( [id://324721]=note: print w/replies, xml ) | Need Help?? |
This is more a joke than a real solution, still might be useful. This builds a Perl routine via eval and then calls it from the content of your own page. It works more or less like a JSP compiler, turning the page data into native source code, and then compiling it via eval. If you add a thin layer of error control, this might be a viable solution. The routine it creates expects a hash containing true/false values (the same you will test in your page) and returns a string with the results. This creates dynamically this code (I reformatted it a bit just to make it more readable): sub page_expr { my (%H) = @_; my $r = ''; if ($H{boys}) { $r .= "  You can play football for the whole day."; if ($H{nice_boys}) { $r .= "  You don't need to get ."; } elsif ($H{agreesive_boys}) { $r .= "  Please respect others"; } else { $r .= "  Please talk to me first"; }; } elsif ($H{girls}) { $r .= "  I suggest you to go to library"; } else { $r .= "  Stay here"; }; return $r; };When run, this program prints:  You can play football for the whole day.  You don't need to get permission from your teacher.Just my euro 0.02. Hope it helps.
In Section
Seekers of Perl Wisdom
|
|