This is a basic Web based Perl Script which helps school and college students to improve their knowledge in Perl Scripting.
If you don’t know what is Factorial, here is a small explanation,
Multiplying given integer with the sequence of descending positive integers is called factorial. For example,
5! is 5 x 4 x 3 x 2 x 1 = 120
So the value of 5! is 120
We can also find the values in the reverse way ie.,
5! is 1 x 2 x 3 x 4 x 5 = 120
In this program we are going to follow the above second method to find the value of the n! (n factorial)
Now, lets see the Perl Script here:
#!/usr/bin/perl -w ##these two lines are used to display errors on browser. If you don't want, you can remove these use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); ##error display ends ##below line is important if you want to display the result in browser print "Content-type: text/html\n\n"; ##HTML Part print ""; ## here is the perl logic starts my $q = new CGI; ## check if a form is submitted with $q->param() if($q->param()) { ##get the param $number = $q->param('number'); $fact = 1; print "Perl CGI Script to find Factorial of a Number Web Based Perl script to Find Factorial of a Number - Tutorialsmade.com
Factorial of ", $number ," is:
"; ##loop till $number is less than equal to $i for($i = 1; $i "; } }
Just go through the inline comments to understand the script.
You can also see the Demo of the above script by clicking the button below:
The post Web Based Perl script to Find Factorial of a Number! appeared first on TutorialsMade.