#!/usr/bin/perl #Is you is, or is you ain't, my foobar? #The dope on scope. baz(); #call baz. sub baz { my $foobar="I feel Baz!\n"; print $foobar; #$foobar is now lexically scoped for #the whole subroutine block. if (1) { #This is another block, it belongs to if. my $foobar="I am the FooMan!\n"; print $foobar; #$foobar is now lexically scoped #for this if block; } print $foobar; if ("I own several pairs of pants") { #That ^^^^ is another if, and this is its block my $foobar="I am the BarMan!\n"; print $foobar; #$foobar is now lexically scoped for this if block; } print $foobar; } #### sub openFile { my @entries; #is now lexically scoped for the entire subroutine; if ($file1) { open FH, "$file1" or die $!; @entries = ; close FH; } if ($file2) { open FH, "$file2" or die $!; @entries = ; #Replace all the entries? what? close FH; } }