- Home
- Interview Questions
- Perl
To round off numbers without printing them, use sprintf. To print numbers with less precision, use printf.
Perl has three false values: 0, the empty string "", and the undefined value.
Perl has different operators for numbers and strings because of its capability to auto-convert scalar values and the differences in handling both those values.
Short-circuiting operators only evaluate their right-side operands when necessary. If the value of the left-side operator determines the overall value of the expression (for example, if the left side of a && operator is false), the expression will stop.
Equality tests return true if the scalars on both sides of the operator are exactly equal. Pattern matching tests result true of the scalar on the left side of the operator contains characters that match the pattern on the right side of the operator.
CGI stands for Common Gateway Interface, and refers to programs that run on the Web server in response to requests from a Web browser (commonly from a form on an HTML page).
The CGI.pm module provides behavior for writing, running, and debugging CGI
scripts. It provides a number of subroutines for managing input to and output from
those scripts as well as other utility subroutines for just about any aspect of CGI
you can think of.
The CGI.pm module is shipped with most current versions of Perl. If it is not
already available as part of your Perl distribution, you can download and install it
from the URL mentioned earlier in this lesson.
To use the CGI module, you import it like you do any other module: with use and
an import tag such as :standard or :all.
Running a CGI script from the command line is usually easier to find the smaller syntax or basic errors you might have made without needing to install the script on the Web server, connect to the Internet, and so on. By running the script on the command line and giving it sample data, you can test your script before actually putting it online.
The param() subroutine is used to find out the values of any form elements on the Web page that called this script. Without any arguments, param() returns a list of keys referring to the names of the form elements. With a key argument (a string), param() returns the value associated with that form element.
You can print HTML code using one of these methods:
-> Use regular print statements. Watch out for embedded quotes!
-> Here document
-> Various subroutines via the CGI.pm module.