xref: /onnv-gate/usr/src/cmd/perl/5.8.4/distrib/t/io/nargv.t (revision 0:68f95e015346)
1*0Sstevel@tonic-gate#!./perl
2*0Sstevel@tonic-gate
3*0Sstevel@tonic-gateprint "1..5\n";
4*0Sstevel@tonic-gate
5*0Sstevel@tonic-gatemy $j = 1;
6*0Sstevel@tonic-gatefor $i ( 1,2,5,4,3 ) {
7*0Sstevel@tonic-gate    $file = mkfiles($i);
8*0Sstevel@tonic-gate    open(FH, "> $file") || die "can't create $file: $!";
9*0Sstevel@tonic-gate    print FH "not ok " . $j++ . "\n";
10*0Sstevel@tonic-gate    close(FH) || die "Can't close $file: $!";
11*0Sstevel@tonic-gate}
12*0Sstevel@tonic-gate
13*0Sstevel@tonic-gate
14*0Sstevel@tonic-gate{
15*0Sstevel@tonic-gate    local *ARGV;
16*0Sstevel@tonic-gate    local $^I = '.bak';
17*0Sstevel@tonic-gate    local $_;
18*0Sstevel@tonic-gate    @ARGV = mkfiles(1..3);
19*0Sstevel@tonic-gate    $n = 0;
20*0Sstevel@tonic-gate    while (<>) {
21*0Sstevel@tonic-gate	print STDOUT "# initial \@ARGV: [@ARGV]\n";
22*0Sstevel@tonic-gate	if ($n++ == 2) {
23*0Sstevel@tonic-gate	    other();
24*0Sstevel@tonic-gate	}
25*0Sstevel@tonic-gate	show();
26*0Sstevel@tonic-gate    }
27*0Sstevel@tonic-gate}
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate$^I = undef;
30*0Sstevel@tonic-gate@ARGV = mkfiles(1..3);
31*0Sstevel@tonic-gate$n = 0;
32*0Sstevel@tonic-gatewhile (<>) {
33*0Sstevel@tonic-gate    print STDOUT "#final \@ARGV: [@ARGV]\n";
34*0Sstevel@tonic-gate    if ($n++ == 2) {
35*0Sstevel@tonic-gate	other();
36*0Sstevel@tonic-gate    }
37*0Sstevel@tonic-gate    show();
38*0Sstevel@tonic-gate}
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gatesub show {
41*0Sstevel@tonic-gate    #warn "$ARGV: $_";
42*0Sstevel@tonic-gate    s/^not //;
43*0Sstevel@tonic-gate    print;
44*0Sstevel@tonic-gate}
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gatesub other {
47*0Sstevel@tonic-gate    print STDOUT "# Calling other\n";
48*0Sstevel@tonic-gate    local *ARGV;
49*0Sstevel@tonic-gate    local *ARGVOUT;
50*0Sstevel@tonic-gate    local $_;
51*0Sstevel@tonic-gate    @ARGV = mkfiles(5, 4);
52*0Sstevel@tonic-gate    while (<>) {
53*0Sstevel@tonic-gate	print STDOUT "# inner \@ARGV: [@ARGV]\n";
54*0Sstevel@tonic-gate	show();
55*0Sstevel@tonic-gate    }
56*0Sstevel@tonic-gate}
57*0Sstevel@tonic-gate
58*0Sstevel@tonic-gatesub mkfiles {
59*0Sstevel@tonic-gate    my @files = map { "scratch$_" } @_;
60*0Sstevel@tonic-gate    return wantarray ? @files : $files[-1];
61*0Sstevel@tonic-gate}
62*0Sstevel@tonic-gate
63*0Sstevel@tonic-gateEND { unlink map { ($_, "$_.bak") } mkfiles(1..5) }
64