http://www.perlmonks.org?node_id=999675


in reply to Re: Replace many array element with another corresponding array element in a file
in thread Replace many array element with another corresponding array element in a file

I tried the following:
my %hashvariable; @hashvariable{@variable} = @vardescription; my $TestText; { local $/; open( my $in, '<', "Test.txt" ) or die "cannot open Test.txt $!"; my $TestText = <$in>; close $in; } $TestText =~ s/$_/$hashvariable{$_}/g for keys %hashvariable; open( my $out, '>', "TestFinal.txt" ) or die "cannot create TestFinal +$!"; print $out $TestText; close $out;
Output file TestFinal.txt is empty. Am I doing anything wrong?
  • Comment on Re^2: Replace many array element with another corresponding array element in a file
  • Download Code

Replies are listed 'Best First'.
Re^3: Replace many array element with another corresponding array element in a file
by Kenosis (Priest) on Oct 18, 2012 at 05:39 UTC

    Oh, sheesh! No, I did something wrong.:

    my $TestText = <$in>;

    should be:

    $TestText = <$in>;

    Sorry about that. Will correct this in the original posting

    BTW - Excellent way to initialize the hash...