I offer some suggestions below.
use strict; use warnings; # no need for your comment! it is clear!! my $outfilename = "pot_temp.txt"; # define an output filename # always check the return values of file operations !!! # there a bunch of syntax'es for this, the main thing is to do it! #open(TFILE,">$outfilename") || die ("unable to open $outfilename $!") +; # below I don't use TFILE, this is just a test to stdout #there are shorter ways to do this, but this is staightforward. #Maybe these are pressure increments? And I have wrong name? #whatever, this is one way to do it... my @temp_increments; for (my $i=500; $i<=900 ; $i += 100) { push @temp_increments, $i; } #my @temp_increments = qw( 500, 600, 700, 800, 900); #would be equivalent for example print "What is the temperature (K)?:"; my $T = <STDIN>; chomp ($T); print "T results are:\n"; foreach my $temp (@temp_increments) { my $theta = $T*((1013/$temp)**(287/1004)); print "temp = $temp theta=$theta \n"; } #Example output...... #C:\TEMP>perl temp.pl #What is the temperature (K)?:26 #T results are: #temp = 500 theta=31.8147304436198 #temp = 600 theta=30.1990838700515 #temp = 700 theta=28.8972548674746 #temp = 800 theta=27.8150092740013 #temp = 900 theta=26.8940943585568
Update: I see that these are pressure increments instead of temperature but no matter. replace @temp_increments with @pressure_increments and my $temp with my $pressure and I think the same numeric result will happen.

The C style for loop is rare in Perl. Strive to use this in as limited of scope and context as possible.


In reply to Re: For loop trouble by Marshall
in thread For loop trouble by cheech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.