I am having difficulty replacing array elements with hash values using the following script. $string appears 8 times in my output file. I want to replace the first occurance with $header{1} amd the second with $header{2} and so on. Any help is appreciated! Thanks!
use Tk; use strict; use warnings; my $mw=new MainWindow; my $filename; my $string; my @data; my $n; 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 $filename="BJSFM_out.prn"; open(OUTPUT, "< $filename") or die "Can't find allowables.txt!"; $string="Laminate Strain Allowables"; @data=<OUTPUT>; $n=1; for (@data) { if ($_ eq $string) { s/$_/$header{$n}/; $n++; } } open (FILE, '>temp.txt'); print FILE @data; close FILE; }
In reply to Replace Array Elements with Hash Values by shortyfw06
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |