- The Perl "print" command dumps the output (simply a string of
characters) of a given CGI form method to output. This same string
can be captured to a Perl string scalar for later use or manipulation
if desired.
- For example, the two constructs shown accomplish exactly the same
thing:
# Print Three Lines of Text
print $query->h1("A header line");
print $query->h1("A Second header line");
print $query->h1("A Third header line");
# Same thing, different way.
$outputString = $query->h1("A header line");
$outputString += $query->h1("A Second header line");
$outputString += $query->h1("A Third header line");
print $outputString;
- Also, you can prebuild arguments to other CGI methods. This is
very helpfull for highly complicated tasks like tables of form fields.
- Anywhere you see the "{}" notation, this is actually a reference
to a hash, so you can predefine a hash and pass a reference to it.
- For example, the two constructs shown accomplish exactly the same
thing:
print "Below should be a left justified image\n";
print $query->hr();
print $query->img({-src=>'/killbill/images/xmms.jpg',
-align=>'left',
-width=>'275',
-height=>'116'});
print "Same image, generated differently\n";
print $query->hr();
my %myHash = ( -src=>'/killbill/images/xmms.jpg',
-align=>'left', -width=>'275', -height=>'116' );
print $query->img(\%myHash);
- Anywhere you see the "[]" notation, this is actually a reference
to an array, so you can predefine an array and pass a reference to it.
- For example, the two constructs shown accomplish exactly the same
thing:
# Try an unorderd list
print $query->hr();
print "This should be a centered unordered list of three elements\n";
print $query->ul({-align=>'center'},
$query->li({-type=>'disc'},
['List Entry One',
'List Entry Two',
'List Entry Three']));
print $query->hr();
# same thing, different way
print "This should be a centered unordered list of three elements\n";
my @listArray = ('List Entry One', 'List Entry Two', 'List Entry Three');
print $query->ul({-align=>'center'},
$query->li({-type=>'disc'},
\@listArray));
print $query->hr();