in reply to Find and replace from two files
You can use hash like so:
use warnings; use strict; use Data::Dumper; my %property_para; open my $fh, '<', "temp.txt" or die "can't open file: $!"; while ( defined( my $line = <$fh> ) ) { chomp $line; my ( $property, $value ) = split /=/, $line; $property_para{$property} = $value; } close $fh or die "can't close: $!"; open $fh, '<', "current.txt" or die "can't open file: $!"; while ( defined( my $line = <$fh> ) ) { chomp $line; my ( $property, $value ) = split /=/, $line; $property_para{$property} = $value if exists $property_para{$prope +rty}; } close $fh or die "can't close: $!"; $Data::Dumper::Varname = 'ADDRESS'; print Dumper \%property_para; # OR my %property_name; open_do_work( 'temp.txt', sub { $property_name{ $_[0] } = $_[1] } ); open_do_work( 'current.txt', sub { $property_name{ $_[0] } = $_[1] if $property_name{ $_[0] } } + ); $Data::Dumper::Varname = 'ADDRESS'; print Dumper \%property_name; sub open_do_work { my ( $file, $coderef ) = @_; open my $fh, '<', $file or die "can't open : $!"; while ( defined( my $line = <$fh> ) ) { chomp $line; my ( $property, $value ) = split /=/, $line; $coderef->( $property, $value ); } }
|
|---|