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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

stupid question involving for loops 1

Status
Not open for further replies.

StormMedic85

Programmer
Sep 7, 2007
20
US
Stupid question...but how come in the loop if I print the array all the numbers in range show up, but outside of the loop only the last one (2454378) does? I'd like to be able to store all of these numbers (julian dates) into an array that I can manipulate the elements of later. Any ideas where I am going wrong? Thanks!

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

$sjdate = "2454374";
$ejdate = "2454379";

for($x=$sjdate; $x < $ejdate; $x++) {
@array = $x;
}


 
Because you're redefining the array each time, rather than adding to it. Try:
Code:
push @array, $x;
 
Ahhhh, ok I understand now. That makes sense. Thanks very much!
 
written simpler as:

Code:
$sjdate = "2454374";
$ejdate = "2454379";
@array = ($sjdate .. $ejdate);




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top