CGI and Perl examples
- To run these scripts
- Form data
- File Handling
- Regular Expressions
- Skywayradio Examples
This page contains a listing of CGI-BIN scripts written in Perl. Many of these scripts have been adapted from scripts found in Elizabeth Castro's lucid book: Perl and CGI for the World Wide Web.
To run these scripts
- Drop the scripts into to the cgi-bin directory of your web server.
- ssh to your server and cd to your cgi-bin directory
- For each *.cgi file run:chmod 755 scriptname.cgi
- Determine the directory path to your Perl interpreter, run:which perl
Compare the output to the first line of each *.cgi file. If the paths are different, change the first line of each offending script to conform to the command output.
- Edit each *.html file and change any directory paths that are incorrect.
Run Code Scalar Assignment inputself.cgi Array assignment days.cgi Loop through an array chores.cgi Print browser info printbrowser.cgi Parse Form Fields parseform.cgi
Run Code Concatenate two scalars concat.cgi Multiply numbers repeat.cgi Divide numbers taxdeduc.cgi Increment a number increment.cgi Raise a number to the nth power exponents.cgi Get remainder modulus.cgi Calculate with parenthesis preference.cgi
Run Code do while dowhile else else elsif elsif for for foreach foreach if if nest nest unless unless until until while while
Run Code Radio Buttons cityinfo.cgi Parse form with foreach namevalue.cgi Get Time gettime.cgi Get Local Time getlocaltime.cgi
Run Code Read from a file readfromlog.cgi Get comments, then write to file chomp.cgi Print key values printkeyvalues.cgi Get exclusive access to a file flock.cgi Send e-mail formmail.cgi Make a directory mkdir.cgi View contents of a directory opendir.cgi Rename a file rename.cgi Write to a file writetolog.cgi chmod a file chmod.cgi
Run Code Display array.cgi Display selected elements getday.cgi Process data from forms split.cgi Slice getmultipledays.cgi Transpose gettoday.cgi Get the number of elements length.cgi Peform math functions modifyall.cgi Sort sort.cgi Reverse sort reverse.cgi Add an element push.cgi Add multiple elements combine.cgi Add an element unshift.cgi Remove the first element shift.cgi Remove the last element pop.cgi Replace an element replaceone.cgi Replace multiple elements replacemore.cgi
Run Code Remove a key-value pair delete.cgi Get each key and value in a hash each.cgi Check to see if a key exists exists.cgi Get several values using keys getmore.cgi Get a value using a key getone.cgi Print all keys and values hash.cgi Get all of a hash's keys keys.cgi Get all values using keys keysvalues.cgi Get all of a hash's values values.cgi
Run Code Base base.cgi EOF eof.cgi Format format.cgi Format HTML formathtml.cgi Format Proper formatproper.cgi Format w/Subs formatwsubs.cgi Get Time gettime.cgi HTML Formatting htmlformatting.cgi List list.cgi
Run Code alternation alternation.cgi Anchor anchor.cgi Asterisk asterisk.html Class class.cgi Class Short classshort.cgi Mand mandn.cgi Match match.cgi Match One matchone.cgi Neg Class negclass.cgi Optional optional.cgi Plus plus.cgi Sequence sequence.cgi Splitr splitr.cgi Substitute substitute.cgi CGI Text use2.cgi Using html using.cgi
Run Code domain domain.cgi expires expires.cgi hidden1 hidden1.cgi hidden2 hidden2.cgi path path.cgi readcookie readcookie.cgi secure secure.cgi sendcookie sendcookie.cgi
Run Code arguments arguments.cgi manretBAD manretBAD.cgi manreturn3 manreturn3.cgi return return.cgi simple simple.cgi
Check out the CPAN module list for an extensive library of pre-written functions.
You can use CPAN to install modules.
- Log in as root
- Using browser, retrieve yourmodule.
- cd /usr/lib/perl5/5.6.0
- Decompress and unpack filegzip -dc modulename.gz | tar -xof -
- Go into the newly-created directory and type: