in reply to Check remote file for size?
Firstly, I'd strongly suggest you consider using the CGI perl module, which will do QUERY_STRING decoding for you. It comes standard with perl, provides many very useful features, and will do a better job than your home-grown encoding (particularly for things like parameters with multiple values).
To answer your question about checking a file's size, you can use the -s operator, like this:
-s returns the file size in bytes if you need that much information.$file = "/path/to/file"; if (-s $file) { # file has non-zero size. } else { # File is empty or does not exist. }
In your particular example, I would suggest opening your file for writing using open(FILE,">$filename"). The ">" will clobber the contents of the file if it exists, as opposed to ">>" which will append to the file. Clobbering the contents means you shouldn't need to care about the file size at all.
Also, there's nothing wrong with using perl modules. In fact, it's very highly recommended. More often than not, re-inventing the wheel results in something which isn't quite as round.
If you're looking at stripping out HTML tags, I'd suggest looking at HTML::Parser, which will do most of the work for you.
If you want your script to die automatically after a certain period of time, you can set an alarm. Unfortunately I don't know how portable this is across non-UNIX operating systems.
If you want your code to always clean up after itself, you can do so with an END block.$SIG{ALRM} = sub { die "Script took too long.\n" }; alarm(60); # Create alarm signal in 60 seconds. # ... do long-running stuff. alarm(0); # Cancel the alarm
An END block runs just before the perl interpretor exits.END { unlink($tmpfile); }
Hope that you find all of the above useful.
Cheers,
Paul