In: Computer Science
5. Create this hash variable: in perl language Scalar => ‘dollar sign’, Array => ‘at sign’, Hash => ‘percent sign’ Process it with a foreach loop that prints the key/value pairs so that the keys are printed in sorted order: Array: at sign Hash: percent sign Scalar: dollar sign.
1. Print scalar variable"
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
my $email = "fnord\@cgi101.com";
my $url = "";
print header;
print start_html("Scalars");
print <<EndHTML;
<h2>Hello</h2>
<p>
My e-mail address is $email, and my web url is
<a href="$url">$url</a>.
</p>
EndHTML
print end_html;
Array: at sign Hash: percent sign Scalar: dollar sign
#!/usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
# declare the colors hash:
my %colors = ( red => "#ff0000", green=> "#00ff00",
blue => "#0000ff", black => "#000000",
white => "#ffffff" );
# print the html headers
print header;
print start_html("Colors");
foreach my $color (keys %colors) {
print "<font color=\"$colors{$color}\">$color</font>\n";
}
print end_html;