use strict; use warnings; use Test::More qw(no_plan); #create a.txt contining "a" open F, "> a.txt"; print F "a"; close F; #fails because no substitution was made #prints to STDOUT process_file(); local $^I = ".bak"; #now it works. #prints to "a.txt" as we want. But how does it know to print there? write_and_read_file(); #ok sub process_file { @ARGV = qw(a.txt); local $/; # slurp it #changes a.txt so contains "b" #the diamond operator operates on @ARGV by default while (<>) { #$_ now contains the entire file, alter at will s/a/b/g; #How does the print operator know what file handle to print to? #Was this selected somewhere by magic? #Where is this documented / explained? print; } #need to reset @ARGV, I guess it got wiped out somewhere in that while. @ARGV = qw(a.txt); while (<>) { is($_,"b"); } }