If you look up $/ in perlvar, you will see
You may set it to a multi-character string to match a multi-character terminator, or to "undef" to read through the end of file.Finally, <DATA> returns the next line from the filehandle DATA, and since $/ is undefined, the entire contents of the file are returned and "caught" in a scalar. UPDATE: i should add that this is one of those few cases where local is a good choice. For example,
Is essentially the same aslocal $/;
Which is not the same aslocal $/ = undef;
Even though that last snippet will be contained inside a do block ... $/ will still be undef afterwards. Try this - make two files foo.txt and bar.txt and run this:$/ = undef;
Then go back and add local to the do block.# print entire file open FH,'foo.txt'; my $foo = do {$/ = undef;<FH>}; print $foo; # print only first line open FH,'bar.txt'; my $bar = <FH>; print $bar;
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
In reply to Re: slurping __DATA__
by jeffa
in thread slurping __DATA__
by LanceDeeply
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |