in reply to Re^4: Delete a line from files
in thread Delete a line from files

These are documented in perlvar Update: the BEGIN block is necessary so that these assignments are executed before the implicit loop by the -p flag, see perlrun

Replies are listed 'Best First'.
Re^6: Delete a line from files
by Anonymous Monk on Oct 13, 2015 at 10:08 UTC
    what is wrong with first opening the file with open and then setting those variables?
      It doesn't work. The diamond operator opens the file and reads from it at the same time, you can't first open the file and then set the variable. Check the difference yourself:
      perl -pwe '$^I = ".bak"; s/[<>]/|/g' file1 perl -pwe 'BEGIN { $^I = ".bak" } s/[<>]/|/g' file2
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ