1  pp_hot.c
2
3  print() on unopened filehandle abc		[pp_print]
4    $f = $a = "abc" ; print $f $a
5
6  Filehandle %s opened only for input		[pp_print]
7    print STDIN "abc" ;
8
9  Filehandle %s opened only for output		[pp_print]
10    $a = <STDOUT> ;
11
12  print() on closed filehandle %s		[pp_print]
13    close STDIN ; print STDIN "abc" ;
14
15  uninitialized					[pp_rv2av]
16	my $a = undef ; my @b = @$a
17
18  uninitialized					[pp_rv2hv]
19	my $a = undef ; my %b = %$a
20
21  Odd number of elements in hash list		[pp_aassign]
22	%X = (1,2,3) ;
23
24  Reference found where even-sized list expected [pp_aassign]
25	$X = [ 1 ..3 ];
26
27  Filehandle %s opened only for output		[Perl_do_readline]
28  	open (FH, ">./xcv") ;
29	my $a = <FH> ;
30
31  glob failed (can't start child: %s)		[Perl_do_readline] <<TODO
32
33  readline() on closed filehandle %s		[Perl_do_readline]
34    close STDIN ; $a = <STDIN>;
35
36  readline() on closed filehandle %s		[Perl_do_readline]
37    readline(NONESUCH);
38
39  glob failed (child exited with status %d%s)	[Perl_do_readline] <<TODO
40
41  Deep recursion on subroutine \"%s\"		[Perl_sub_crush_depth]
42    sub fred { fred() if $a++ < 200} fred()
43
44  Deep recursion on anonymous subroutine 	[Perl_sub_crush_depth]
45    $a = sub { &$a if $a++ < 200} &$a
46
47  Use of reference "%s" as array index [pp_aelem]
48    $x[\1]
49
50__END__
51# pp_hot.c [pp_print]
52use warnings 'unopened' ;
53$f = $a = "abc" ;
54print $f $a;
55no warnings 'unopened' ;
56print $f $a;
57use warnings;
58no warnings 'unopened' ;
59print $f $a;
60EXPECT
61print() on unopened filehandle abc at - line 4.
62########
63# pp_hot.c [pp_print]
64use warnings 'unopened' ;
65$SIG{__WARN__} = sub { warn $_[0] =~ s/\0/\\0/rug; };
66print {"a\0b"} "anc";
67print {"\0b"} "anc";
68EXPECT
69print() on unopened filehandle a\0b at - line 4.
70print() on unopened filehandle \0b at - line 5.
71########
72# pp_hot.c [pp_print]
73use warnings 'io' ;
74# There is no guarantee that STDOUT is output only, or STDIN input only.
75# Certainly on some BSDs (at least FreeBSD, Darwin, BSDi) file descriptors
76# 1 and 2 are opened read/write on the tty, and the IO layers may reflect this.
77# So we must make our own file handle that is read only.
78my $file = "./xcv" ; unlink $file ;
79open (FH, ">$file") or die $! ;
80close FH or die $! ;
81die "There is no file $file" unless -f $file ;
82open (FH, "<$file") or die $! ;
83print FH "anc" ;
84open(FOO, "<&FH") or die $! ;
85print FOO "anc" ;
86no warnings 'io' ;
87print FH "anc" ;
88print FOO "anc" ;
89use warnings 'io' ;
90print FH "anc" ;
91print FOO "anc" ;
92close (FH) or die $! ;
93close (FOO) or die $! ;
94unlink $file ;
95EXPECT
96Filehandle FH opened only for input at - line 12.
97Filehandle FOO opened only for input at - line 14.
98Filehandle FH opened only for input at - line 19.
99Filehandle FOO opened only for input at - line 20.
100########
101# pp_hot.c [pp_print]
102$SIG{__WARN__} = sub { warn $_[0] =~ s/\0/\\0/rug; };
103use warnings 'io' ;
104my $file = "./xcv" ; unlink $file ;
105open (FH, ">$file") or die $! ;
106close FH or die $! ;
107die "There is no file $file" unless -f $file ;
108open ("a\0b", "<$file") or die $! ;
109print {"a\0b"} "anc" ;
110open ("\0b", "<$file") or die $! ;
111print {"\0b"} "anc" ;
112close "a\0b" or die $! ;
113close "\0b" or die $! ;
114unlink $file ;
115EXPECT
116Filehandle a\0b opened only for input at - line 9.
117Filehandle \0b opened only for input at - line 11.
118########
119# pp_hot.c [pp_print]
120use warnings 'closed' ;
121close STDIN ;
122print STDIN "anc";
123opendir STDIN, ".";
124print STDIN "anc";
125closedir STDIN;
126no warnings 'closed' ;
127print STDIN "anc";
128opendir STDIN, ".";
129print STDIN "anc";
130use warnings;
131no warnings 'closed' ;
132print STDIN "anc";
133EXPECT
134print() on closed filehandle STDIN at - line 4.
135print() on closed filehandle STDIN at - line 6.
136	(Are you trying to call print() on dirhandle STDIN?)
137########
138# pp_hot.c [pp_print]
139# [ID 20020425.012 (#9030)] from Dave Steiner <steiner@bakerst.rutgers.edu>
140# This goes segv on 5.7.3
141use warnings 'closed' ;
142my $fh = *STDOUT{IO};
143close STDOUT or die "Can't close STDOUT";
144print $fh "Shouldn't print anything, but shouldn't SEGV either\n";
145EXPECT
146print() on closed filehandle __ANONIO__ at - line 7.
147########
148# pp_hot.c [pp_print]
149package foo;
150use warnings 'closed';
151open my $fh1, "nonexistent";
152print $fh1 42;
153open $fh2, "nonexistent";
154print $fh2 42;
155open $bar::fh3, "nonexistent";
156print $bar::fh3 42;
157open bar::FH4, "nonexistent";
158print bar::FH4 42;
159EXPECT
160print() on closed filehandle $fh1 at - line 5.
161print() on closed filehandle $fh2 at - line 7.
162print() on closed filehandle $fh3 at - line 9.
163print() on closed filehandle FH4 at - line 11.
164########
165# pp_hot.c [pp_rv2av]
166use warnings 'uninitialized' ;
167my $a = undef ;
168my @b = @$a;
169no warnings 'uninitialized' ;
170my @c = @$a;
171EXPECT
172Use of uninitialized value $a in array dereference at - line 4.
173########
174# pp_hot.c [pp_rv2hv]
175use warnings 'uninitialized' ;
176my $a = undef ;
177my %b = %$a;
178no warnings 'uninitialized' ;
179my %c = %$a;
180EXPECT
181Use of uninitialized value $a in hash dereference at - line 4.
182########
183# pp_hot.c [pp_aassign]
184use warnings 'misc' ;
185my %X ; %X = (1,2,3) ;
186no warnings 'misc' ;
187my %Y ; %Y = (1,2,3) ;
188EXPECT
189Odd number of elements in hash assignment at - line 3.
190########
191# pp_hot.c [pp_aassign]
192use warnings 'misc' ;
193my %X ; %X = [1 .. 3] ;
194no warnings 'misc' ;
195my %Y ; %Y = [1 .. 3] ;
196EXPECT
197Reference found where even-sized list expected at - line 3.
198########
199# pp_hot.c [Perl_do_readline]
200use warnings 'closed' ;
201close STDIN        ; $a = <STDIN> ;
202opendir STDIN, "." ; $a = <STDIN> ;
203closedir STDIN;
204no warnings 'closed' ;
205opendir STDIN, "." ; $a = <STDIN> ;
206$a = <STDIN> ;
207EXPECT
208readline() on closed filehandle STDIN at - line 3.
209readline() on closed filehandle STDIN at - line 4.
210	(Are you trying to call readline() on dirhandle STDIN?)
211########
212# pp_hot.c [Perl_do_readline]
213use warnings 'closed' ;
214close STDIN        ; $a .= <STDIN> ;
215opendir STDIN, "." ; $a .= <STDIN> ;
216closedir STDIN;
217no warnings 'closed' ;
218opendir STDIN, "." ; $a .= <STDIN> ;
219$a = <STDIN> ;
220EXPECT
221readline() on closed filehandle STDIN at - line 3.
222readline() on closed filehandle STDIN at - line 4.
223	(Are you trying to call readline() on dirhandle STDIN?)
224########
225# pp_hot.c [Perl_do_readline]
226use warnings 'io' ;
227my $file = "./xcv" ; unlink $file ;
228open (FH, ">$file") or die $! ;
229my $a = <FH> ;
230no warnings 'io' ;
231$a = <FH> ;
232use warnings 'io' ;
233open(FOO, ">&FH") or die $! ;
234$a = <FOO> ;
235no warnings 'io' ;
236$a = <FOO> ;
237use warnings 'io' ;
238$a = <FOO> ;
239$a = <FH> ;
240close (FH) or die $! ;
241close (FOO) or die $! ;
242unlink $file ;
243EXPECT
244Filehandle FH opened only for output at - line 5.
245Filehandle FOO opened only for output at - line 10.
246Filehandle FOO opened only for output at - line 14.
247Filehandle FH opened only for output at - line 15.
248########
249# pp_hot.c [Perl_sub_crush_depth]
250use warnings 'recursion' ;
251sub fred
252{
253    fred() if $a++ < 200
254}
255{
256  local $SIG{__WARN__} = sub {
257    die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
258  };
259  fred();
260}
261EXPECT
262ok
263########
264# pp_hot.c [Perl_sub_crush_depth]
265no warnings 'recursion' ;
266sub fred
267{
268    fred() if $a++ < 200
269}
270{
271  local $SIG{__WARN__} = sub {
272    die "ok\n" if $_[0] =~ /^Deep recursion on subroutine "main::fred"/
273  };
274  fred();
275}
276EXPECT
277
278########
279# pp_hot.c [Perl_sub_crush_depth]
280use warnings 'recursion' ;
281$b = sub
282{
283    &$b if $a++ < 200
284}  ;
285
286&$b ;
287EXPECT
288Deep recursion on anonymous subroutine at - line 5.
289########
290# pp_hot.c [Perl_sub_crush_depth]
291no warnings 'recursion' ;
292$b = sub
293{
294    &$b if $a++ < 200
295}  ;
296
297&$b ;
298EXPECT
299########
300# pp_hot.c [pp_concat]
301use warnings 'uninitialized';
302my($x, $y);
303sub a { shift }
304a($x . "x");	# should warn once
305a($x . $y);	# should warn twice
306$x .= $y;	# should warn once
307$y .= $y;	# should warn once
308EXPECT
309Use of uninitialized value $x in concatenation (.) or string at - line 5.
310Use of uninitialized value $x in concatenation (.) or string at - line 6.
311Use of uninitialized value $y in concatenation (.) or string at - line 6.
312Use of uninitialized value $y in concatenation (.) or string at - line 7.
313Use of uninitialized value $y in concatenation (.) or string at - line 8.
314########
315# pp_hot.c [pp_aelem]
316{
317use warnings 'misc';
318print $x[\1];
319}
320{
321no warnings 'misc';
322print $x[\1];
323}
324
325EXPECT
326OPTION regex
327Use of reference ".*" as array index at - line 4.
328########
329# pp_hot.c [pp_aelem]
330package Foo;use overload q("") => sub {};package main;$a = bless {}, "Foo";
331$b = {};
332{
333use warnings 'misc';
334print $x[$a];
335print $x[$b];
336}
337{
338no warnings 'misc';
339print $x[$a];
340print $x[$b];
341}
342
343EXPECT
344OPTION regex
345Use of reference ".*" as array index at - line 7.
346########
347use warnings 'misc';
348use constant FOO => { a => 1 };
349() = $_[FOO->{a}];
350
351EXPECT
352########
353use warnings 'misc';
354use constant FOO => {};
355() = $_[FOO];
356
357EXPECT
358OPTION regex
359Use of reference "HASH\(0x\w+\)" as array index at - line 3.
360