talexb has asked for the wisdom of the Perl Monks concerning the following question:
While fixing a Nagios ntp script this afternoon, I encountered something odd. Here's the test script I reduced the behaviour to:
When run, this produces#!/usr/bin/perl -w use strict; # Test to see if $. really does break when reading from DATA. { foreach (<DATA>) { print "Try line $.:$_"; } } __DATA__ This is line 1. This is the second line. Here is line 3. The last line is line 4.
except that I was expecting[alex@foo bar]$ perl -w test2.pl Try line 4:This is line 1. Try line 4:This is the second line. Try line 4:Here is line 3. Try line 4:The last line is line 4.
What's happening? Why isn't $. showing me the correct input line number for the data?[alex@foo bar]$ perl -w test2.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: Odd behaviour with $. and <DATA>
by Tanktalus (Canon) on Jan 16, 2006 at 20:31 UTC | |
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 |