See p. 68 of the third edition of the Camel book... "The __DATA__ token functions similarly to the __END__ token, but opens the DATA filehandle within the current package's namespace, so that files you require can each have their own DATA filehandles open simultaneously. For more information, see DATA in Chapter 28."
HTH, 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 Phillip Richcreek Sent: Wednesday, May 02, 2012 8:56 AM 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? TIA, Phil > use warnings; > use constant {SECS_PER_DAY => 24 * 60 * 60}; use POSIX qw{strftime}; > > my $startDate = strftime "%Y-%m-%d_", localtime(); my $endDate = > strftime "%Y-%m-%d_", localtime(time + 2 * SECS_PER_DAY); my $dateRE = > qr{\d{4}-\d{2}-\d{2}_}; > > while (my $line = <DATA>) { > if ($line =~ m/^start_date/) { > $line =~ s/$dateRE/$startDate/g; > } > elsif ($line =~ /^end_date/) { > $line =~ s/$dateRE/$endDate/g; > } > print $line; > } > > __DATA__ > First line > start_date = '2012-04-29_00:00:00', '2012-04-29_00:00:00', > '2012-04-29_00:00:00', end_date = '2012-05-01_00:00:00', > '2012-05-01_00:00:00', '2012-05-01_00:00:00', Last line > > HTH > > -- > Brian Raven _______________________________________________ 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