Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Opening and closing files in loop

by kcott (Canon)
on Oct 22, 2012 at 08:49 UTC ( #1000292=note: print w/replies, xml ) Need Help??

in reply to Opening and closing files in loop

G'day lt007,

Welcome to the monastery.

Rather than continually changing the default filehandle with select, I'd use print with the required filehandle (e.g. print $fh qq{...}). Using this method, you only need to open the files once before the loop and close them once after the loop.

Your question title (Opening and closing files in loop) suggests you're maybe confused between select and open. You don't use open in your loop nor show any code where it is used.

You don't show how $max gets its value. This variable controls how many times the loop is entered. Try print "$max\n"; just before the loop to test this.

Did you intend to put an ampersand in front of randomPwd($nmbchars)? See perlsub for what it does and whether you need it (normally you don't).

-- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1000292]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (11)
As of 2016-10-21 17:58 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.