in reply to Inserting Code Before an -n/-p Loop

I somehow remember seeing it in the perldocs, but not sure where.

What's happening is that the snippet is literally injected into a loop (see perlrun)

}{ is just closing the loops body and opening a block to pair with the old end.

Nota bene that using BEGIN and END blocks have similar effects but are probably easier to read.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

update

from perlrun#*-n*

  • -n

    causes Perl to assume the following loop around your program, which makes it iterate over filename arguments somewhat like sed -n or awk:

    LINE: while (<>) { ... # your program goes here }

    ...

    BEGIN and END blocks may be used to capture control before or after the implicit program loop, just as in awk.