|
| Recent
Articles |
Whatever, Perl 6 Is On The Way Larry Wall's recent State of the Onion address concerned Perl 6 and the concept of being prepared to do "whatever" in the context of the next version of the language.
The Hidden Loop Programmers use loops to avoid writing repetitive code, but sometimes forget that compilers will unroll their loops when possible for efficiency. You can unroll your own loops, too. Rather than testing and...
Webmin, Usermin Need Updates The French Security Incident Response Team (FrSIRT) has reported a pair of vulnerabilities in Webmin and Usermin that could be exploited by remote attackers. FrSIRT said in its advisory that the pair of flaws pose...
Seeing Perl In Google Code Google's release of a code repository for open source projects has a number of languages represented, including Perl. Perl -- It's like Java, only it lets you deliver on time and under budget. -- quote seen...
Perl Plus Jifty Equals Hiveminder Yes, Jifty is another web application builder, and yes, Hiveminder is another to-do list; but it is Perl that made them possible. A post by Jesse Vincent at UsePerl announced the public debut of Hiveminder.
Why Perl Scripts? First let me tell you the history of Perl scripts and then I will go into why I think Perl is the best overall programming language that there is. Perl is a programming language created by Larry Wall in 1987.
Perl Bootcamp Saddles Up For Germany The next Big Nerd Ranch session of Perl Bootcamp occurs in Germany in September, and will cover Intermediate Perl. Once again, Learning Perl (4th ed.) and Intermediate Perl co-author brian d foy will lead...
|
 |
| Recent WebProNews Articles |
Google And YouTube, The Morning After
With a lot of attention paid to the big number, $1.65 billion, there are some other numbers that illustrate Google's interest in YouTube much better than the price tag. Google CEO Eric Schmidt probably isn't having second thoughts about the acquisition of YouTube.
Pew: Web 2.0 Is Web 1.0
Pew Internet and American Life Project released a six-page analysis of Web 2.0, attempting to define, exactly, what types of Internet applications the phrase covers. The end result: like porn, we know Web 2.0 when we see it; and Web 2.0 has been here since Web 1.0.
Google Book Scans Boosting Sales
The search advertising company has contended its practice of scanning books and presenting snippets of text would help drive interest and sales of books people might not find normally, and it is starting to look like Google was correct.
MySpace Sees Old People More than half of the users on young, hip, advertising magnet MySpace may be older than 35, a revelation that could be damaging to Fox Interactive Media's attempts to demand premium rates for ads aimed at what has been touted as a young demographic.
Ron Moore On Podcasting And Battlestar Galactica
The ballroom was standing room only at the Podcast and Portable Media Expo, the crowd was electric waiting to hear from two of their idols; first TWiT host Leo Laporte, and topped off with the executive producer of Battlestar Galactica, Ron Moore, who would speak of being called...
Blip.tv Gives Glimpse Of TV Future Blip.tv co-founder and COO Dina Kaplan has no shortage of energy. She's a five-three or so bottle of Jolt Cola, shaken up and gushing forth about her company, which is proud to host the unboomed Amanda Congdon's...
|
|
10.10.06
Continuation Lines
By
A.P. Lawrence
There's been a long standing Unix convention of breaking long lines with a "\" to make them easier to read.
You'd almost always see this in files like /etc/printcap, but there are plenty of other places where this convention is used.
A file with continuations might look like this:
This \
is \
one \
line.
and any program reading that is supposed to see it as:
This is one long line.
The "\" is supposed to immediately precede the line feed with no blanks, spaces or anything else between. This rigidity sometimes causes problems when folks use GUI editors to change files; they don't notice the extra spaces and subsequently programs fail.
Bash (and ksh) handle these lines by default. Using the file above as input, we can write a simple script and get one line as output:
$ while read line; do echo $line; done < t
This is one line.
$
If we use "read -r", however, it's different:
$ while read -r line; do echo $line; done < t
This \
is \
one \
line.
$
Adding spaces after each "\" produces something yet again different:
# (spaces added to file)
$ while read line; do echo $line; done < t
This
is
one
line.
$
The missing "\"'s are because now they are simply seen as quoting the spaces. But if you use "read -r" on the same file, it's not seen as quoted:
# (same file, extra spaces after \)
$ while read -r line; do echo $line; done < t
This \
is \
one \
line.
Perl
Given Perl's strong Unix roots, you might think it would recognize this convention also or at least have some funky variable you could set or unset. Nope:
$ cat t.pl
#!/usr/bin/perl
while (<>)
{
print ;
}
# (original file, no spaces after \)
$ ./t.pl < t
This \
is \
one \
line.
$
Section 8.1 of my Perl Cookbook presents an example program that looks for \'s, strips them and gathers full lines.
Apache groks continuation lines, and you can find stuff scattered around for more general cases: Matching line continuation characters.
Interestingly, the Perl debugger does understand backslash continuation: (from "`perldoc perldebug"):
Multiline commands
If you want to enter a multi-line command, such as a subroutine definition with several statements or a format, escape the new-line that would normally end the debugger command with a back-slash. Here's an example:
DB<1> for (1..4) { \
cont: print "ok\n"; \
cont: }
ok
ok
ok
ok
Note that this business of escaping a newline is specific to interactive commands typed into the debugger.*Originally published at APLawrence.com
|