in reply to (Ovid) Re: CGI Uploads, again!
in thread CGI Uploads, again!

Ovid,
Thanks first for wrangling this code - your solutions worked really well. I have a couple of questions about your code, if you don't mind enlightening me, I'd appreciate it. (Always an apprentice!)
The most important question is why did you switch from the object oriented form of CGI to the function-oriented form?
Second question is using sysopen rather than open? I know that sysopen in general provides for more control - locking, etc. Is it generally better to use it than regular open?
Thanks!

Replies are listed 'Best First'.
(Ovid) Re(3): CGI Uploads, again!
by Ovid (Cardinal) on Oct 16, 2001 at 03:15 UTC

    To answer your questions: I switched from the object-oriented interface to the function oriented interface because you were using both and I decided to stick with one or the other:

    use CGI ':all'; use Fcntl; use strict; my $q = new CGI; print header, start_html('file upload'), h1('file upload');

    From the snippet above, you can see that you're instantiating a new CGI object but you're also using the start_html and h1 functions that you've imported into your namespace with ":all". There are other examples in your program, but I decided to just use the function-oriented interface as it makes the code look a bit cleaner (though there are times that the object-oriented interface can give you some fine-grained control that the function oriented interface cannot). If I were to have switched to the OO interface, the above snippet would have looked like this:

    use CGI; use Fcntl; use strict; my $q = CGI->new; print $q->header, $q->start_html('file upload'), $q->h1('file upload');

    To be frank, the reason I used sysopen is because that's what you were using :) I wasn't really focusing on making sure that everything was exactly what you needed. I was just trying to get the darned thing to work.

    sysopen has the advantage of offering finer control over opening files than open. For instance, you can open files with sysopen and specify that they not exist when you try to open that. With open, you have to add extra code to test for existence of the file.

    Cheers,
    Ovid

    Vote for paco!

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.