I tried this with constraints: I didn't want to use -i nor $^I.

Requirements:

File::Inplace
File::Flock.

A dir "in_place"
A file "abc.txt".
A file "adc.txt".
Both files should be in the dir "in_place".

#!/usr/bin/perl use strict; use warnings; use File::Copy; use File::Inplace; use File::Spec; use File::Flock; my $dir = '/root/Desktop/in_place'; my $data_dir = sub { File::Spec->catfile($dir, shift); }; my $abc_file = "/root/Desktop/in_place/abc.txt"; my $adc_file = "/root/Desktop/in_place/adc.txt"; lock($abc_file, 'shared', 'nonblocking'); lock($adc_file, 'shared', 'nonblocking'); my $edit = new File::Inplace(file => $data_dir->("abc.txt"), suffix => + ".log"); quick_change($edit, hello => 'jello'); $edit->commit; my $lock = File::Flock->new($edit); lock($lock, 'abc.txt.log'); lock_rename($lock, 'abc.txt.log'); unlock('abc.txt.log'); sub quick_change { my $edit = shift; my $from = shift; my $to = shift; while ($edit->has_lines) { my $line = $edit->next_line; if ($line eq $from) { $edit->replace_line($to); } } }
abc.txt:
hello
adc.txt:
jello

In reply to Re: flock on on $^I by Khen1950fx
in thread flock on on $^I by Anonymous Monk

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.