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.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
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |