in reply to Re: Replace data in the column of one file with corresponding ones in another file
in thread Replace data in the column of one file with corresponding ones in another file

thank you, but it is giving me this error when I run the script Can't locate File/Slurp.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at 2FilesFindReplace.pl line 1.
  • Comment on Re^2: Replace data in the column of one file with corresponding ones in another file

Replies are listed 'Best First'.
Re^3: Replace data in the column of one file with corresponding ones in another file
by wind (Priest) on Jan 27, 2011 at 23:03 UTC
    The version not relying on File::Slurp would be the following:
    use Tie::File; use strict; my $file1 = 'file1.txt'; my $file2 = 'file2.txt'; open my $fh, $file2 or die "Can't open $file2: $!"; my %hash = map { chomp; my @data = split /\s+/; $data[0] => $data[2]; } <$fh>; tie my @array, 'Tie::File', $file1 or die "Can't open $file1: $!"; foreach (@array) { s{^(\S*\s+)(\S+)}{ if (exists $hash{$2}) { print "Replacing $2 with $hash{$2}\n"; $1 . $hash{$2}; } else { print "Can't find $2, not changing\n"; $1 . $2; } }e; }
    - Miller
Re^3: Replace data in the column of one file with corresponding ones in another file
by ww (Archbishop) on Jan 28, 2011 at 02:15 UTC
    So File::Slurp is not installed.

    Download and install it.