This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Patch to JPL example program
[perl5.git] / t / pragma / warn / pp_hot
CommitLineData
599cee73
PM
1 pp_hot.c AOK
2
3 Filehandle %s never opened
4 $f = $a = "abc" ; print $f $a
5
6 Filehandle %s opened only for input
7 print STDIN "abc" ;
8
af8c498a
GS
9 Filehandle %s opened only for output
10 print <STDOUT> ;
599cee73
PM
11
12 print on closed filehandle %s
13 close STDIN ; print STDIN "abc" ;
14
15 uninitialized
16 my $a = undef ; my @b = @$a
17
18 uninitialized
19 my $a = undef ; my %b = %$a
20
21 Odd number of elements in hash list
22 %X = (1,2,3) ;
23
24 Reference found where even-sized list expected
25 $X = [ 1 ..3 ];
26
af8c498a 27 Read on closed filehandle %s
599cee73
PM
28 close STDIN ; $a = <STDIN>;
29
30 Deep recursion on subroutine \"%s\"
31 sub fred { fred() if $a++ < 200} fred()
32
33 Deep recursion on anonymous subroutine
34 $a = sub { &$a if $a++ < 200} &$a
35
36__END__
37# pp_hot.c
38use warning 'unopened' ;
39$f = $a = "abc" ;
40print $f $a
41EXPECT
42Filehandle main::abc never opened at - line 4.
43########
44# pp_hot.c
45use warning 'io' ;
46print STDIN "anc";
af8c498a
GS
47print <STDOUT>;
48print <STDERR>;
49open(FOO, ">&STDOUT") and print <FOO>;
50print getc(STDERR);
51print getc(FOO);
52read(FOO,$_,1);
599cee73
PM
53EXPECT
54Filehandle main::STDIN opened only for input at - line 3.
af8c498a
GS
55Filehandle main::STDOUT opened only for output at - line 4.
56Filehandle main::STDERR opened only for output at - line 5.
57Filehandle main::FOO opened only for output at - line 6.
58Filehandle main::STDERR opened only for output at - line 7.
59Filehandle main::FOO opened only for output at - line 8.
60Filehandle main::FOO opened only for output at - line 9.
599cee73
PM
61########
62# pp_hot.c
63use warning 'closed' ;
64close STDIN ;
65print STDIN "anc";
66EXPECT
67print on closed filehandle main::STDIN at - line 4.
68########
69# pp_hot.c
70use warning 'uninitialized' ;
71my $a = undef ;
72my @b = @$a
73EXPECT
74Use of uninitialized value at - line 4.
75########
76# pp_hot.c
77use warning 'uninitialized' ;
78my $a = undef ;
79my %b = %$a
80EXPECT
81Use of uninitialized value at - line 4.
82########
83# pp_hot.c
84use warning 'unsafe' ;
85my %X ; %X = (1,2,3) ;
86EXPECT
87Odd number of elements in hash assignment at - line 3.
88########
89# pp_hot.c
90use warning 'unsafe' ;
91my %X ; %X = [1 .. 3] ;
92EXPECT
93Reference found where even-sized list expected at - line 3.
94########
95# pp_hot.c
96use warning 'closed' ;
97close STDIN ; $a = <STDIN> ;
98EXPECT
af8c498a 99Read on closed filehandle main::STDIN at - line 3.
599cee73
PM
100########
101# pp_hot.c
102use warning 'recursion' ;
103sub fred
104{
105 fred() if $a++ < 200
106}
4a925ff6
GS
107{
108 local $SIG{__WARN__} = sub {
109 die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
110 };
111 fred();
112}
599cee73 113EXPECT
4a925ff6 114ok
599cee73
PM
115########
116# pp_hot.c
117use warning 'recursion' ;
118$b = sub
119{
120 &$b if $a++ < 200
121} ;
122
123&$b ;
124EXPECT
125Deep recursion on anonymous subroutine at - line 5.