Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
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 drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2015-07-02 16:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (44 votes), past polls