#!/usr/local/bin/perl -w use strict; print "Content-type: text/plain\n\n"; print "This file demonstrates how to initialize variables\n\n"; my $output = generate_page(); print $output; print "\nThis is the output of the program\n\n"; eval ("sub main {$output}"); main(); sub generate_page { my $output = <<'PAGE'; my ($first, $second); $first = 7; $second = "hello"; print "\$first = $first; \$second = $second\n"; $first = $second; print "\$first = $first; \$second = $second\n"; $first = "wonderful"; $second = 43; print "\$first = $first; \$second = $second\n"; $first = 0; $second = ""; print "\$first = $first; \$second = $second\n"; my (@list, $value, $temp); $list[0] = 3; $list[1] = 4; $list[2] = 0; $list[5] = 6; foreach $value (0 .. $#list) { $temp = defined $list[$value] ? $list[$value] : "undef"; print "\$list[$value] = $temp "; } print "\n"; my (@sublist); @sublist = @list[0..1,5]; foreach $value (0 .. $#sublist) { $temp = defined $sublist[$value] ? $sublist[$value] : "undef"; print "\$sublist[$value] = $temp "; } print "\n"; ($first,$second,@sublist) = @list; print "\$first = $first \$second = $second "; foreach $value (0 .. $#sublist) { $temp = defined $sublist[$value] ? $sublist[$value] : "undef"; print "\$sublist[$value] = $temp "; } print "\n"; my %data; $data{Wilma} = "Betty"; $data{Fred} = "Barney"; $data{Dino} = "Sabertooth"; foreach $value (keys %data) { print "\$data{\'$value\'} = $data{$value} "; } print "\n"; %data = ( "Miami" => "FL", "Boston" => "MA", "New York" => "NY"); foreach $value (keys %data) { print "\$data{\'$value\'} = $data{$value} "; } print "\n"; my $key; while ( ($key,$value) = each %data) { print "City: $key, State: $value "; } print "\n"; PAGE return $output; }