[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] closing filehandles, redirecting output?



Okay,

I'm creating a CGI that accepts input from a form for a particular username.
What I want it to do is to compare the form username with usernames already
on file and conditionally return different information. Not too difficult,
right? Well, I'm having difficulty determining how the filehandles affect
STDOUT.

If I don't apply a filehandle to a print statement, it will be directed to
STDOUT, right? So this will work:

open (USERS, "userfile.dat") || &catastrophicFailure;
while ($file=<USERS>) {
        chop($file);
        $file=~s/\W.*//;               # just get username part
        if ($form{'user'} eq $file) {  #$form{'user'} is from cgi parse
                print "Content-type: text/html\n\n";
                print <<"done";
                        <HTML><HEAD><TITLE>Oops, Try Again!</TITLE></HEAD>
                        <BODY><H1>Oops, that's already taken</H1>
                        <H3>Press your browser's <I>BACK</I> button and 
                        select a different username</H3>
                        </BODY></HTML>
                done
                exit(0);
        } else {
                &createPassword;
        }
close (USERS);

Since I'm fairly new (WAY NEW) to MacPerl and Perl in general, when I first
coded this I was worried about printing with <USERS> open, but now that I
think about it, the print statements are directed to the handle so it's not
a problem. What might be a problem is that I'm performing an "exit(0)"
before I "close(USERS)"

Is *THAT* bad, or will exit(0) force a close?

[Daniel]

Daniel Hedrick                                 mailto:daniel@icorp.net
ICorp Web Development                            http://www.icorp.net/
----------------------------------------------------------------------
           *-*-*-*-*-Monday, September 30, 1996-*-*-*-*-*
(1960) Howdy Doody's last show
(1955) James Dean, actor, died in a car crash
(1939) First manned rocket flight (by auto maker Fritz von Opel)
(1659) Robinson Crusoe shipwrecked