Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^2: Replace many array element with another corresponding array element in a file

by faezshingeri (Initiate)
on Oct 18, 2012 at 05:31 UTC ( #999675=note: print w/ replies, xml ) Need Help??


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
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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999675]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2014-08-23 04:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (172 votes), past polls