Works fine here:
Note how I removed the foreach and replaced with while. The foreach will slurp the file in (<DATA> in list context) and then loop through the list. while, however, is evaluating in scalar context, which means read one line, deal with it, move to the next line.$ cat x.pl #!/usr/bin/perl -w use strict; # Test to see if $. really does break when reading from DATA. { #foreach (<DATA>) { print "Try line $.:$_"; } while(<DATA>) { print "Try line $.:$_"; } } __DATA__ This is line 1. This is the second line. Here is line 3. The last line is line 4.$ perl ./x.pl Try line 1:This is line 1. Try line 2:This is the second line. Try line 3:Here is line 3. Try line 4:The last line is line 4.$
In reply to Re: Odd behaviour with $. and <DATA>
by Tanktalus
in thread Odd behaviour with $. and <DATA>
by talexb
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |