1#!./perl 2 3# tests for DATA filehandle operations 4 5BEGIN { 6 chdir 't' if -d 't'; 7 require "./test.pl"; 8 set_up_inc('../lib'); 9} 10 11$|=1; 12 13# It is important that all these tests are run via fresh_perl because 14# that way they get written to disk in text mode and will have CR-LF 15# line endings on Windows. Otherwise the failures related to Perl 16# code being read in binary mode will not be observed. 17 18run_multiple_progs('', \*DATA); 19 20done_testing(); 21 22__END__ 23# http://rt.perl.org/rt3/Ticket/Display.html?id=28106#txn-82657 24while (<DATA>) { 25 chomp; 26 print "$.: '$_'\n"; 27 system(); 28} 29__DATA__ 301 312 323 33EXPECT 341: '1' 352: '2' 363: '3' 37######## 38# http://rt.perl.org/rt3/Ticket/Display.html?id=28106#txn-83113 39my $line1 = <DATA>; 40`echo foo`; 41my $line2 = <DATA>; 42if ($line1 eq "one\n") { print "ok 1\n" } else { print "not ok 1\n" } 43if ($line2 eq "two\n") { print "ok 2\n" } else { print "not ok 2\n" } 44__DATA__ 45one 46two 47EXPECT 48ok 1 49ok 2 50######## 51# http://rt.perl.org/rt3/Ticket/Attachment/828796/403048/perlbug.rep.txt 52my @data_positions = tell(DATA); 53while (<DATA>){ 54 if (/^__DATA__$/) { 55 push @data_positions, tell(DATA); 56 } 57} 58 59my @fh_positions; 60open(my $fh, '<', $0) or die; 61while (<$fh>){ 62 if (/^__DATA__$/) { 63 push @fh_positions, tell($fh); 64 } 65} 66 67print "not " unless "@data_positions" eq "@fh_positions"; 68print "ok"; 69 70__DATA__ 71ab 72__DATA__ 73ab 74 75__DATA__ 76ab 77__DATA__ 78lotsa junk 79nothing 80EXPECT 81ok 82######## 83# Which package is __DATA__ in? 84package foo; 85BEGIN{*foo::=*bar::} 86print <DATA>; 87__DATA__ 88123 89EXPECT 90123 91