RE: Inline test data
Henry Hartley <[email protected]> Wed, 2 May 2012 17:23:20 +0000
| Newsgroups | gmane.comp.lang.perl.active-perl |
|---|---|
| Message-ID | <[email protected]> |
perldoc SelfLoader -- Henry -----Original Message----- From: Phillip Richcreek Sent: Wednesday, May 02, 2012 12:53 PM I don't have the camel book and could not find an online version. I also don't see anything in the doc that ships with the perl installation. But I did find this at http://perldoc.perl.org/SelfLoader.html#The-__DATA__-token and it helps: "The __DATA__ token tells the perl compiler that the perl code for compilation is finished. Everything after the __DATA__ token is available for reading via the filehandle FOOBAR::DATA..." "Everything after the __DATA__ token is available for reading..." is the part that I was unsure about. Now I know! Thanks, Phil On Wed, May 2, 2012 at 10:01 AM, Rothenmaier, Deane <[email protected]> wrote: > 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: [email protected] > [mailto:[email protected]] On Behalf Of > Phillip Richcreek > Sent: Wednesday, May 02, 2012 8:56 AM > To: [email protected] > 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 > [email protected] > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs > _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs