in reply to Odd behaviour with $. and <DATA>
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.$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Odd behaviour with $. and <DATA>
by talexb (Chancellor) on Jan 16, 2006 at 20:35 UTC | |
by ikegami (Patriarch) on Jan 16, 2006 at 21:22 UTC | |
by blazar (Canon) on Jan 17, 2006 at 08:54 UTC |