This raises an interesting (well, to me, anyway) question: if a program's 
pulling data from a __DATA__ section, will it quit reading when it gets to an 
__END__ tag? Or will it run right over it?

Another thought: if you put a __DATA__ <I>after</I> an __END__, what'll happen? 
(pardon me if I'm having a Steven Wright moment...)

Deane Rothenmaier
Programmer/Analyst - IT-StdCfg
Walgreens Corp.
2 Overlook Point #N51022D
MS 6515
Lincolnshire, IL 60069
224-542-5150

The more corrupt the republic, the more numerous the laws. -- Tacitus


-----Original Message-----
From: activeperl-boun...@listserv.activestate.com 
[mailto:activeperl-boun...@listserv.activestate.com] On Behalf Of Brian Raven
Sent: Wednesday, May 02, 2012 12:38 PM
To: activeperl@listserv.activestate.com
Subject: RE: Inline test data


> From: activeperl-boun...@listserv.activestate.com [mailto:activeperl- 
> boun...@listserv.activestate.com] On Behalf Of Phillip Richcreek
> Sent: 02 May 2012 14:56
> To: activeperl@listserv.activestate.com
> Subject: Inline test data
>
> A recent post used a nice feature for providing test data to a script.
> (See __DATA__ below) I've seen it before but never understood it. How 
> does it work? What signals the end of the data to the  while (my $line 
> = <DATA>) { ? Is this a type of here document? Can someone point me 
> where it's descibed in the perl doc?

That's a good question. It took me a while to find it, but see the Special 
Literals section in 'perldoc perldata'.

The __DATA__ is just a marker to tell the perl compiler that there is no more 
code after this point. The DATA file handle is the same one used by the 
compiler when it stopped parsing (or a duplicate), so the next read will be the 
first line after __DATA__. You can read all the way to the end of the source 
file. In fact you can rewind (perldoc -f seek) the DATA file handle and read 
the script from the beginning, if you want. For (a trivial) example...

use strict;
use warnings;

seek DATA, 0, 0;
while (<DATA>) {
    print;
}
__DATA__

HTH

--
Brian Raven

Please consider the environment before printing this e-mail.

This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy.

Any unauthorised copying, disclosure or distribution of the material in this 
e-mail is strictly forbidden.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to