Perl – Web hit function using LWP::UserAgent

Published on Author gryzliLeave a comment

Often I need to issue web hit from a perl code, and re-inventing the wheel with LWP::UserAgent or WWW::Curl::Easy sometimes is too overdose for me.  That’s why I decided to write some semi-universal function called “web_hit()” which could be easily used for issuing web hits.


Important notices:

  • The function always generates POST requests
  • The arguments which are accepted are as follows:
    • URL – this must be the first argument
    • POST_DATA – this must be the second argument, and could be reference to a HASH. The keys of the hash will be used as variable names, and the values as values.
    • \$result – Reference to a result variable, where you will get back the results


Here is the definition itself:

web_hit() definition


The usage is pretty straight-forward, here are some examples:


Leave a Reply

Your email address will not be published. Required fields are marked *

Captcha * Time limit is exhausted. Please reload CAPTCHA.