This program is to prompt the user for a temperature and use the input to compute potential temperature at each pressure level from 500 to 1000 in increments of 100. I used:
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";
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.
Thanks to those that offered advice to my last "Improve my Coding" post. I tried to implement some suggestions.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.