Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl Array Question...

Status
Not open for further replies.

StormMedic85

Programmer
Sep 7, 2007
20
US
In the second foreach loop, I simply want to apply each value in the array into that equation. It appears to be combining them. I can't find a good internet reference. Any help would be appreciated.

#!/usr/local/bin/perl -w

use strict;

my (@temps, $item, $MYFILE, $val, $es);

@temps = ('-12', '-13', '-14', '-15');

&vaporpressure();

sub vaporpressure

{

foreach $item(@temps) {

$item += 273.15;

}

foreach $val(@temps) {

$es = 611.2*exp(5417*((1/273.15)-(1/$val)));

}

print $es;

}

exit;
 
I'm not sure I'm following you, but $es will be the last value of the loop because you print it outside the loop block.

Code:
foreach $val (@temps) {

$es = 611.2*exp(5417*((1/273.15)-(1/$val)));

}

print $es;

Is that what you meant to do?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Ooops! That would be the problem. :-X

Thanks...although I'm now embarrassed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top