Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^3: Replace Array Elements with Hash Values

by shortyfw06 (Beadle)
on Jun 13, 2012 at 18:13 UTC ( #976038=note: print w/replies, xml ) Need Help??

in reply to Re^2: Replace Array Elements with Hash Values
in thread Replace Array Elements with Hash Values

I tried to run the following and it replaces $string with %header rather than $string with $header[0], $header1, etc. Also, I thought my print command would add the newlines but it doesn't.

use Tk; use strict; use warnings; my $mw=new MainWindow; my @header = ("FHT_neg45","FHT_0","FHT_45","FHT_90","OHT_neg45","OHT_0 +","OHT_45","OHT_90"); my $button = $mw->Button(-text=>"temp", -command=> \&button)->pack(); MainLoop; sub button { #Read BJSFM_out.prn into an array @data my $filename="BJSFM_out.prn"; open my $fh, '<', $filename or die "Can't find $filename!"; my $string="1DO YOU WANT INSTRUCTIONS?"; my @data= map {chomp; $_ } <$fh>; my $n=0; for (@data) { if ($_ eq $string) { $data[$n] = $header[$n]; $n++; } } open my $write_fh, '>', 'temp.txt' or die $!; print $write_fh join " ",@data,"\n"; close $write_fh; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976038]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-01-23 21:01 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (254 votes). Check out past polls.