cheech has asked for the wisdom of the Perl Monks concerning the following question:
The file gets written fine, but the results are bogus so the problem is in the loop. Specifically, I get three identical values for $theta and $i, and I should get 5 different values.my (@thetas, @press); my ($i); use strict; use warnings; my $outfilename = "pot_temp.txt";# define an output filename open(TFILE,">$outfilename"); print "What is the temperature (K)? \n"; my $T = <STDIN>; chomp ($T); for ($i=500, $i=900 , $i += 100) { my $theta = $T*((1013/$i)**(287/1004)); push (@press, $i); push (@thetas,$theta); } print TFILE "A T of $T results in thetas of @thetas at the pressure le +vels @press \n";
Thanks to those that offered advice to my last "Improve my Coding" post. I tried to implement some suggestions.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: For loop trouble
by graff (Chancellor) on Jun 13, 2009 at 17:21 UTC | |
|
Re: For loop trouble
by Utilitarian (Vicar) on Jun 13, 2009 at 16:47 UTC | |
by cheech (Beadle) on Jun 13, 2009 at 16:55 UTC | |
by JavaFan (Canon) on Jun 13, 2009 at 17:03 UTC | |
by afoken (Chancellor) on Jun 13, 2009 at 17:14 UTC | |
by cheech (Beadle) on Jun 13, 2009 at 18:03 UTC | |
by afoken (Chancellor) on Jun 13, 2009 at 17:07 UTC | |
by ikegami (Patriarch) on Jun 13, 2009 at 20:02 UTC | |
|
Re: For loop trouble
by Marshall (Canon) on Jun 14, 2009 at 05:16 UTC |