1#!./perl 2 3BEGIN { 4 chdir 't' if -d 't'; 5 @INC = '../lib'; 6 require "./test.pl"; 7} 8 9print "1..5\n"; 10 11my $j = 1; 12for $i ( 1,2,5,4,3 ) { 13 $file = mkfiles($i); 14 open(FH, "> $file") || die "can't create $file: $!"; 15 print FH "not ok " . $j++ . "\n"; 16 close(FH) || die "Can't close $file: $!"; 17} 18 19 20{ 21 local *ARGV; 22 local $^I = '.bak'; 23 local $_; 24 @ARGV = mkfiles(1..3); 25 $n = 0; 26 while (<>) { 27 print STDOUT "# initial \@ARGV: [@ARGV]\n"; 28 if ($n++ == 2) { 29 other(); 30 } 31 show(); 32 } 33} 34 35$^I = undef; 36@ARGV = mkfiles(1..3); 37$n = 0; 38while (<>) { 39 print STDOUT "#final \@ARGV: [@ARGV]\n"; 40 if ($n++ == 2) { 41 other(); 42 } 43 show(); 44} 45 46sub show { 47 #warn "$ARGV: $_"; 48 s/^not //; 49 print; 50} 51 52sub other { 53 no warnings 'once'; 54 print STDOUT "# Calling other\n"; 55 local *ARGV; 56 local *ARGVOUT; 57 local $_; 58 @ARGV = mkfiles(5, 4); 59 while (<>) { 60 print STDOUT "# inner \@ARGV: [@ARGV]\n"; 61 show(); 62 } 63} 64 65my @files; 66sub mkfiles { 67 foreach (@_) { 68 $files[$_] ||= tempfile(); 69 } 70 my @results = @files[@_]; 71 return wantarray ? @results : @results[-1]; 72} 73 74END { unlink_all map { ($_, "$_.bak") } mkfiles(1..5) } 75