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.

In reply to Re: "Updating" files. by GrandFather
in thread "Updating" files. by neutron

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.