# # Perl __DATA__
APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

2004/01/13 __DATA__

I've removed advertising from most of this site and will eventually clean up the few pages where it remains.

While not terribly expensive to maintain, this does cost me something. If I don't get enough donations to cover that expense, I will be shutting the site down in early 2020.

If you found something useful today, please consider a small donation.



Some material is very old and may be incorrect today

© January 2004 Tony Lawrence

In a Perl script, this indicates the end of executable code. Whatever is beyond this is not interpreted or checked by "perl -c":


#!/usr/bin/perl
foreach (@ARGV) {
  print "$_\n";
  }
__DATA__

whatever you like {{{{
}
 

The stuff beyond __DATA__ can be accessed by your code:

#!/usr/bin/perl
foreach (@ARGV) {
  print "$_\n";
  }
while (<DATA>) {
  print;
}
__DATA__

whatever you like {{{{
}
 

That can be useful for small chunks of data you want to carry with a program, but it's also handy while writing code: stash samples from data files where you can easily review them, or read in code from elsewhere you want to cut and paste from.

Another use is in debugging: "perl -c" is pretty smart, and can often tell you the line number you screwed up on. However, if you are fumble-fingered like me, and type in a bunch of code at once without checking, you can get Perl so confused that it has no idea where you went wrong. I'm always doing something like this:

if ($something eq "red" } {
 ...

}
 

($something eq "red" should close with a ")", not "}").

Tuck a few of those in your code and "perl -c" won't help you much. So I isolate the problem by moving __DATA__ to just under the main code. If "perl -c" doesn't belch, the problem is in a subroutine somewhere. Move __DATA__ under the first subroutine and try again. Once it does complain, you know the problem is above - move __DATA__ up until you don't see it, and you've isolated the problem area. Sometimes I have to get into code sections, which may require adding a "}" on the line above, but I'll usually spot my error before it gets that bad.


If you found something useful today, please consider a small donation.



Got something to add? Send me email.





(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

->
-> Perl __DATA__


Inexpensive and informative Apple related e-books:

Take Control of Numbers

Take Control of iCloud

Take Control of Pages

Photos for Mac: A Take Control Crash Course

Take Control of Apple Mail, Third Edition





More Articles by © Tony Lawrence





Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us


Printer Friendly Version





After establishing competence and ability, your customer wants to know that you are honest and that you care about their needs. Sell that, because that's what they really want to buy. (Tony Lawrence)




Linux posts

Troubleshooting posts


This post tagged:

Perl

Programming

Scripting

Troubleshooting

UnixWords



Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode