On Fri, 2004-02-06 at 08:45, [EMAIL PROTECTED] wrote:
> What does the construct "}{" mean? As in
>
>
> $ perl -pe ' } { $_="foo\n"' /dev/null
> foo
>
> I figure it has to do with how the -p switch affects the script that
> is passed to the interpreter. Is this documented anywhere?
perldoc perlrun:
-n causes Perl to assume the following loop around your
program, which makes it iterate over filename argu-
ments somewhat like sed -n or awk:
LINE:
while (<>) {
... # your program goes here
}
Note that the lines are not printed by default. See
-p to have lines printed.
The docs aren't speaking metaphorically; the while construct is
*literally* assembled around your code. So the example you gave above
results in:
LINE:
while (<>) {
} { $_="foo\n"
}
I think this might be documented more explicitly in perlfaq somewhere.
For a practical example, try this:
perl -pe '}{print "$.\n"' .bashrc
(Substitute another filename for ".bashrc" if appropriate.)
--
Craig S. Cottingham
[EMAIL PROTECTED]