in reply to flock on on $^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".
abc.txt:#!/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); } } }
adc.txt:hello
jello
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: flock on on $^I
by Anonymous Monk on Aug 19, 2010 at 13:53 UTC | |
by Anonymous Monk on Aug 19, 2010 at 14:37 UTC |