in reply to update values in one file from another
This is my bet at it:
use warnings; use strict; my %fed; open my $fd, '<', 'file2' or die "open: $!"; $fed{$1}++ while <$fd> =~ m/^(\w+)\s/; close $fd; open $fd, '<', 'file1' or die "open: $!"; open my $fd2, '>', '/tmp/file1.tmp' or die "open: $!"; ## FIXME: tmpf +ile while (<$fd>) { m/^(\w+)\s+(\d+)$/; printf $fd2 "$1\t%d\n", exists $fed{$1} ? $2+1 : $2; } close $fd2; close $fd; rename '/tmp/file1.tmp', 'file1' or warn "rename: $!";
I've tried editing file1 inplace using $^I and <> but didn't get anything.
--
David Serrano
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: update values in one file from another
by GrandFather (Saint) on Dec 07, 2005 at 10:13 UTC | |
by Hue-Bond (Priest) on Dec 07, 2005 at 11:06 UTC | |
by Anonymous Monk on Dec 08, 2005 at 09:50 UTC | |
by Anonymous Monk on Dec 08, 2005 at 10:15 UTC | |
by Anonymous Monk on Dec 08, 2005 at 10:39 UTC |