I think given the context of the example in the
Camel that the behavior is correct. I do think it is a
poor example for someone that is new to Perl.
Prior to the example it is stated that suppose we had
a file that had \ at the end of a line to indicate that is
continued on the next line. This is common in shell scripts.
Your examples are assuming
that the lines do not have a space before the \ character,
again this is not typical in shell scripts. So perhaps a good
example of a file would be:
find ./ --name igloo.txt | \
xargs ls -l $1 | \
grep 'Dec'
Now that is a pointless shell script, but it illustrates the
use of the \ at the end of a line that I think might be
what the example in the book is refering to.
A more readable example would be:
Hello Cold Cruel \
World. Are you ready
to take a trip to \
the mall with me
for some very delicious ice cream?
I think this will make for a delightful day, \
don't you?
it would "do the right thing", which is get the next
line of the file and append it to the previous lines
before it enters the
# now process $_ block if the
pattern match is a success.
So the eof is needed to prevent it from reading past it,
since in effect the
redo conditional is superseding the
while statement. That
is if I am understanding the
redo function correctly.
Revised example:
while (<DATA>) {
chomp;
if (s/\\//) {
$_ .= <DATA>;
redo unless eof; # don't read past each file's eof
}
# now proces $_
print $_ . "\n";
}
__DATA__
Hello Cold Cruel \
World. Are you ready
to take a trip to \
the mall with me
for some very delicious ice cream?
I think this will make for a delightful day, \
don't you?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.