Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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

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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://999675]
help
Chatterbox?
[Lady_Aleena]: Would you use a module that is almost 150 characters to type with the use and importing all subroutines?
[LanX]: use module :all ?
[Lady_Aleena]: Lax, that would take it down to a little less than 100 characters. The module name is nearly 80 characters long.
Lady_Aleena has fumble fingers today.
[Lady_Aleena]: Sorry for the name typo LanX.
[LanX]: never lad_ena!
[LanX]: ;)
[Lady_Aleena]: IMO, Fancy::Join:: Grammatical isn't bad, but RolePlaying:: WorldBuilding:: WorldBuildersGuide book::ClimateTerra inSubsistance is on the long side.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2017-05-24 21:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?