############################################################################# # # Script: infix-postfix.pl # Author: Premshree Pillai # Description: Using this script you can : # - Convert an Infix expression to Postfix # - Convert a Postfix expression to Infix # - Evaluate a Postfix expression # - Evaluate an Infix expression # Web: http://www.qiksearch.com # E-mail: qiksearch@rediffmail.com # Created: 23/09/02 (dd/mm/yy) # # © 2002 Premshree Pillai. All rights reserved. # ############################################################################ sub init { @string=split(/&/,$ENV{QUERY_STRING}); @exp=split(/=/,$string[0]); $expression=$exp[1]; # Convert the HTML encoding $expression =~ tr/+/ /; $expression =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $expression =~ s///g; # Convert HTML stuff as necessary. $expression =~ s/<([^>]|\n)*>//g; @act=split(/=/,$string[1]); $action=$act[1]; } init(); print '
';
print 'Infix-Postfix '; print ''; print ''; if(($exp[0] ne 'expression') || ($act[0] ne 'action')) { print "Please use the above form!"; } else { if(!(($action eq '0') || ($action eq '1') || ($action eq '2') || ($action eq '3'))) { print "Invalid Argument for Action"; } else { print ''; if($action eq '0') { print 'Postfix Expression : ',InfixToPostfix($expression),''; } if($action eq '1') { print 'Infix Expression : ',PostfixToInfix($expression),''; } if($action eq '2') { print 'Postfix Eval : ',PostfixEval($expression),''; } if($action eq '3') { print 'Infix Eval : ',eval($expression),''; } print ''; } } print ' Algorithms used »'; print '© 2002 Premshree Pillai.'; print ' Sign my Guestbook | Qiksearch.com'; print ''; print ' |