in reply to Critque my second script for me?
I don't care for calling exit in a subroutine. Suppose you want to log accesses where the password doesn't match. You would have to edit bad_hacker_no_cookie(), at least to remove the exit, or even to do the report. I'd rather write a new subroutine (log_password_mismatch()) and exit in the if clause.
You don't have to unflock files. It'll happen automatically when Perl closes the file. That avoids a race condition, as well.
It can be helpful to print the name of the file along with $! (if an open or close or flock fails) instead of a cute error message. You may remember that "WANK WANK: No such file or directory" means that the header can't be found now, but in a month that memory may be gone.
print while <FH>; is gentler on memory than slurping a file into an array and then printing each line. If you think about it, you can avoid holding the new news file in memory with a clever use of unlink and rename.
I don't like declaring lexical variables until they're needed. That's a style thing.
Be careful stringifying things that don't need to be stringified. Check a couple of your open statements.
If you must print raw HTML in big chunks, use a heredoc.
That's a lot more than I thought I'd say when I started, but if there's anything that stands out as a warning, it's what Hero mentioned. Just because you use lexical variables doesn't mean they're not prone to the same mishaps as true globals. You're just less likely to lose the whole leg. Maybe a toe or two.
|
|---|