in reply to Re: update values in one file from another
in thread update values in one file from another
You can doi it like this:
use warnings; use strict; # Create a test file open outFile, ">", "file1.txt"; print outFile <<end; rabbit 1 hen 0 pig 2 cow 2 sheep 5 end close outFile; my %fed; $fed{$1}++ while <DATA> =~ m/^(\w+)\s/; local @ARGV = ('file1.txt'); local $^I = '.bak'; while (<>) { m/^(\w+)\s+(\d+)$/; printf "$1\t%d\n", exists $fed{$1} ? $2+1 : $2; } __DATA__ rabbit feed 10kg used on 21/10/2005 by consumer1 cow feed 100kg used on 11/11/2005 by consumer1 sheep feed 50kg used on 24/11/2005 by consumer3
file1.txt contains:
rabbit 2 hen 0 pig 2 cow 3 sheep 6
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: update values in one file from another
by Hue-Bond (Priest) on Dec 07, 2005 at 11:06 UTC | |
|
Re^3: update values in one file from another
by Anonymous Monk on Dec 08, 2005 at 09:50 UTC | |
|
Re^3: update values in one file from another
by Anonymous Monk on Dec 08, 2005 at 10:15 UTC | |
by Anonymous Monk on Dec 08, 2005 at 10:39 UTC |