G'day Mosley,

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:

$file = "/path/to/file"; if (-s $file) { # file has non-zero size. } else { # File is empty or does not exist. }
-s returns the file size in bytes if you need that much information.

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.

$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
If you want your code to always clean up after itself, you can do so with an END block.
END { unlink($tmpfile); }
An END block runs just before the perl interpretor exits.

Hope that you find all of the above useful.

Cheers,
Paul


In reply to Re: Check remote file for size? by pjf
in thread Check remote file for size? by Mosley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.