Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Here there be cammels!

by Anonymous Monk
on Feb 28, 2015 at 23:46 UTC ( [id://1118212]=note: print w/replies, xml ) Need Help??


in reply to Here there be cammels!

I have tried setting $.

Interestingly:

while (<DATA>) { chomp; warn "<$_>"; } warn "One"; $. = 123; warn "Two"; close DATA; warn "Three"; $. = 456; warn "Four"; __DATA__ Zero

Gives:

<Zero> at - line 1, <DATA> line 1. One at - line 2, <DATA> line 1. Two at - line 4, <DATA> line 123. Three at - line 6. Four at - line 8, <DATA> line 456.

And yet, it's a hack. Better to implement the message yourself.

Replies are listed 'Best First'.
Re^2: Here there be camels!
by LanX (Saint) on Mar 01, 2015 at 00:04 UTC
    > And yet, it's a hack.

    Looks like a bug for me, though DATA is closed it's reported at FOUR.

    Only b/c a line-number is set.

    > Better to implement the message yourself.

    Well, yeah, undocumented behavior. :)

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    PS: Je suis Charlie!

      I do not think is a bug: is a edge case of use of very particular features...
      diamond <> never close the handle and __DATA__ is very near to be $0 in this case (if i remember you can seek it and print the main program too). Because you can adjust $. and you had not closed DATA handle you end with the beahviour observed.
      from perldata
      Text after __DATA__ may be read via the filehandle PACKNAME::DATA , where PACKNAME is the package that was current when the __DATA__ token was encountered. The filehandle is left open pointing to the line after __DATA__. The program should close DATA when it is done reading from it.
      
      PS. thanks for the line directive hint: never eard about..
      L*

      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

        Using DATA was just an example, the same thing happens on a normal filehandle too.

        system 'echo "foo" >/tmp/blah'; open my $fh, '<', '/tmp/blah' or die $!; while (<$fh>) { chomp; warn "<$_>"; } warn "One"; $. = 123; warn "Two"; close $fh; warn "Three"; $. = 456; warn "Four"; __END__ <foo> at - line 3, <$fh> line 1. One at - line 4, <$fh> line 1. Two at - line 6, <$fh> line 123. Three at - line 8. Four at - line 10, <$fh> line 456.

        So LanX is probably right about it being more of a bug than an obscure feature :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1118212]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2024-04-16 08:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found