in reply to "Updating" files.

The "short hand" is a Perl one liner designed to be run from the command line. The -i.bak puts an in place edit loop around the code provided with -e and does the same thing as $^I = "myinfo.txt.bak"; is intended to do (but doesn't, see below for a correct version).

The diamond operator uses a file handle or, if none is provided, opens file handles for each file name in @ARGV (generally those provided on the command line). Your code mixes the two distinct usages. Consider instead:

use strict; use warnings; my $filename = 'myinfo.txt'; # Create the test file open my $outFile, '>', $filename or die "Failed to create $filename: $ +!"; print $outFile <<FILE; Program name: some junk Author: dude Company: no name Phone: 123.345.1234 Version: 1.0 FILE close $outFile; # 'Edit' the file local @ARGV = $filename; local $^I = '.bak'; while (<>) { next if /^Phone:/; s/^Author:.*/Author: Johny5/; print; }

which updates myinfo.txt to contain:

Program name: some junk Author: Johny5 Company: no name Version: 1.0

and generates myinfo.txt.bak with the original contents of myinfo.txt.


Perl's payment curve coincides with its learning curve.