CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Opening and closing files in loop

 



lt007
New User

Oct 22, 2012, 1:33 AM

Post #1 of 3 (580 views)
Opening and closing files in loop Can't Post

Hey, I've got some problems with a little program. I want to write into 2 files but the ouput-structure differs inside those two.

I use this code:

Code
    for ($i=1;$i<=$max;$i++){  

$pwd = &randomPwd($nmbchars);
select (DB);
print qq("$dept$w$i","7 days","$pwd",,,,,,\n);
close(DB);
select (newDB);
print qq("$dept$w$i"\t>\t"$pwd"\n);
close(newDB);

}

The loop just runs 1 time and then the program stops. It should run multiple times.

Is there a restriction in opening and closing files inside a loop?


gerble1000
User

Oct 22, 2012, 1:46 AM

Post #2 of 3 (579 views)
Re: [lt007] Opening and closing files in loop [In reply to] Can't Post

what is the value of $max
i am only a beginner but i think the sintax for the loop is this

for (my $i=1; $i<$max; $i++)


try this


Code
    for (my $i=0; $i < $max; $i++){   

$pwd = &randomPwd($nmbchars);
select (DB);
print qq("$dept$w$i","7 days","$pwd",,,,,,\n);
close(DB);
select (newDB);
print qq("$dept$w$i"\t>\t"$pwd"\n);
close(newDB);

}



(This post was edited by gerble1000 on Oct 22, 2012, 1:57 AM)


Laurent_R
Veteran / Moderator

Oct 22, 2012, 4:17 AM

Post #3 of 3 (571 views)
Re: [gerble1000] Opening and closing files in loop [In reply to] Can't Post

I don't think this will work any better.

@IT007: why don't you simply use file handlers to write to your files?

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives