in reply to if value not matches replace it with other value

Hi perladdicted,

Please enclose your code with <code> and </code> tags for better readability.

The code below basically does what you need. You can change the if and print statements in according to your needs.

#!/usr/bin/perl my %hash; open FH, "master.cfg" or die $!; while (<FH>) { chomp; my ($k, $v) = split /=/; $hash{$k} = $v; } close FH; open FH1, "config1.cfg" or die $!; while (<FH1>) { chomp; my ($key1, $value1) = split /=/; if ( defined $hash{$key1} and $hash{$key1} ne $value1) { print "$key1=$value1\n"; } } close FH1;

Replies are listed 'Best First'.
Re^2: if value not matches replace it with other value
by Laurent_R (Canon) on Dec 30, 2014 at 11:06 UTC
    Please note that your syntax for opening files works, but is somewhat obsolete. It is better to use the three-argument syntax and to use lexical filehandles. Something like this:
    my $infile = "master.cfg"; open my $FH, "<", $infile or die "could not open $infile $!";
    You of course have to adapt other places of your code where you use the filehandles (to use $FH instead of FH).