Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re^3: Replace Array Elements with Hash Values

by Cristoforo (Curate)
on Jun 13, 2012 at 18:19 UTC ( #976041=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

Just an observation. List::MoreUtils has a function apply which does the chomp and passes the modified, (line less the newline), line to @data

my @data= apply {chomp} <$fh>;.


Update: Or more simply, chomp(my @data = <$fh>);

Replies are listed 'Best First'.
Re^4: Replace Array Elements with Hash Values
by shortyfw06 (Beadle) on Jun 13, 2012 at 18:36 UTC

    I figured it out. Thank you for all of the help!

    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; foreach my $line (@data) { if ($line eq $string) { $line = $header[$n]; $n++; } } open my $write_fh, '>', 'temp.txt' or die $!; print $write_fh join "\n",@data; close $write_fh; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://976041]
[CPUlidster]: Is the glass pyramid still in glasgow
[robby_dobby]: CPUlidster: Eh, what? That's Louvre, right?
[CPUlidster]: 20yrs since I visited.

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2017-12-15 10:57 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (431 votes). Check out past polls.