Perl coding to PHP coding conversion
Posted
by Haskella
on Stack Overflow
See other posts from Stack Overflow
or by Haskella
Published on 2010-05-15T05:11:20Z
Indexed on
2010/05/15
5:14 UTC
Read the original article
Hit count: 495
Hi, I am trying to convert some Perl into PHP using this guideline: http://www.cs.wcupa.edu/~rkline/perl2php/#basedir
Basically I know next to nothing about these two languages. Please give me some simple English explanation of what each line does, I'll be more than happy. Thanks for reading :D
Perl CGI program:
#!/usr/bin/perl -T
use strict;
use warnings;
use CGI ();
my %fruit_codes = (
apple => '2321.html',
banana => '1234.html',
coconut => '8889.html',
);
my $c = CGI->new;
my $fruit_parameter = $c->param('fruit_name');
my $iframe_document;
if (defined $fruit_parameter and exists $fruit_codes{$fruit_parameter}) {
$iframe_document = $fruit_codes{$fruit_parameter};
} else {
$iframe_document = 'sorry-no-such-fruit.html';
}
$c->header('application/xhtml+xml');
print <<"END_OF_HTML";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Fruits</title>
</head>
<body>
<form action="fruits.cgi">
<fieldset>
<label for="fruit">Name of the fruit:</label>
<input id="fruit" name="fruit_name" type="text" />
<input type="submit" />
</fieldset>
</form>
<iframe src="$iframe_document">
<a href="$iframe_document">resulting fruit</a>
</iframe>
</body>
</html>
END_OF_HTML
1;
© Stack Overflow or respective owner