in reply to A Little review for a little DBI and CGI?

48: open HTML, "startpage" || die "opening startpage: $!\n";

That should be or instead of ||. Common mistake which means your die will never run. This is the only serious error I found (though repeated a few times).

49: print while(<HTML>);

I was going to suggest an alternative here but I decided I actually like your method best.

50: close HTML || die "closing startpage: $!\n";

I tend to use warn rather than die when reporting a failure of close. Usually close only fails when a buffer flush fails (usually due to lack of disk space) so there are cases where you want to take more drastic action, but I don't see this as one of them.

All in all a pretty clean chunk of code.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: A Little review for a little DBI and CGI?
by coolmichael (Deacon) on Mar 28, 2001 at 13:46 UTC
    It isn't that I doubt you, but I've been getting die error messages from the script while testing it. I tried a few things on the command line

    C:\WINDOWS\Desktop>perl -e "2==1 or die qw(dying)" dying at -e line 1. C:\WINDOWS\Desktop>perl -e "2==1 || die qw(dying)" dying at -e line 1. C:\WINDOWS\Desktop>
    I'm using ActiveState Perl v5.6.0 on win98 (above) and 5.005_03 linux below
    [michael@subtext michael]$ perl -e "2==1 or die qw(dying);" dying at -e line 1. [michael@subtext michael]$ perl -e "2==1 || die qw(dying);" dying at -e line 1.
    My copy of the camel is at work (second perl book I bought, the first one was the llama). I'll see what it says about || and or tomorrow.

    update:You're completly right Tye. I didn't know the brackets would change things. I've made the change as you suggested.

    Also, thank you for your comments. In the reply, I forgot to thank you. That'll teach me to post at 1:00 am.

    Edit: chipmunk 2001-03-30

      open HTML, "startpage" || die "opening startpage: $!\n";

      is parsed as: open HTML, ( "startpage" || die "opening startpage: $!\n" ) but the expression "startpage" is always true so the die will never be executed. To test, just change "startpage" to "smartmage" or some other non-existant file name.

      The problem is a matter of precedence.

      An alternate solution is: open( HTML, "startpage" ) || die "opening startpage: $!\n"; but I'd still use or for that for the sake of robustness (in case someone comes along and remove the parens).

              - tye (but my friends call me "Tye")