in reply to Opening and closing files in loop
Is there a restriction in opening and closing files inside a loop?
You aren't opening the files within the loop.
select only makes a particular, already open, filehandle the default for print.
But you are closeing those handles on the first pass, and they never get re-opened.
Two possibilities:
for ($i=1;$i<=$max;$i++){ $pwd = &randomPwd($nmbchars); select (DB); print qq("$dept$w$i","7 days","$pwd",,,,,,\n); select (newDB); print qq("$dept$w$i"\t>\t"$pwd"\n); }
for ($i=1;$i<=$max;$i++){ $pwd = &randomPwd($nmbchars); print DB qq("$dept$w$i","7 days","$pwd",,,,,,\n); print newDB qq("$dept$w$i"\t>\t"$pwd"\n); }
Personally, I prefer the latter option.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Opening and closing files in loop
by lt007 (Initiate) on Oct 22, 2012 at 08:42 UTC |