#!/usr/bin/perl
# how and how not to use my to make subroutine variables local
# this example turns the perl script into html
# and runs and shows the output
#
print "Content-type: text/html\n\n";
print "<HTML><TITLE>using the my operator, local scope variables</TITLE>\n";
print "<PRE>\n";	# set up formatted text
# show this source and then the results
#
$code = `cat $0`;	# load source code of this ($0) script into $code
$code =~ s/</</g;    # convert < and > to html special chars
$code =~ s/>/>/g;
print $code;		# send source code to browser
print "<HR>\n";		# draw a nice horizontal bar
########
#  now run the examples that show how my works
print "example 1 - do not use, my likes parens for multiple variables\n";
$a = "a1";
$b = "b1";
{my $a,$b,$c; print "first: [$a] [$b] [$c]\n";}
print "last one: $a $b\n";
print "example 2 - do not use, my likes parens for multiple variables on both sides of assignment\n";
$a = "a1";
$b = "b1";
{my ($a,$b,$c) = 3; print "first: [$a] [$b] [$c]\n";}
print "last one: $a $b\n";
print "example 3 - single local initialized, use this\n";
$a = "a1";
$b = "b1";
{my $a = 3; print "first: [$a] [$b] [$c]\n";}
print "last one: $a $b\n";
print "example 4 - multiple locals initialized, use this\n";
$a = "a1";
$b = "b1";
{my ($a,$b,$c) = (1,2,3); print "first: [$a] [$b] [$c]\n";}
print "last one: $a $b\n";

print "</HTML>\n";
exit;

example 1 - do not use, my likes parens for multiple variables first: [] [b1] [] last one: a1 b1 example 2 - do not use, my likes parens for multiple variables on both sides of assignment first: [3] [] [] last one: a1 b1 example 3 - single local initialized, use this first: [3] [b1] [] last one: a1 b1 example 4 - multiple locals initialized, use this first: [1] [2] [3] last one: a1 b1