user1074051 user1074051 - 6 days ago 5
Perl Question

how to retrive a perl file using wget and execute it using a one-liner?

I'm looking to use wget to retrieve a perl file and execute it in one line. Does anyone know if this is possible/how I would go about doing this?

Answer

In order to use wget for this purpose, you would use the -O flag and give it the '-' character as an argument. From the manpage:

-O file
--output-document=file

Giving '-' as the "file" option to -O tells it to send it's output to stdout, which can then be piped into the Perl command.

You can provide the -q flag as well to turn off wget's own warning and message output:

-q
--quiet
   Turn off Wget's output.

This will make things look cleaner in the shell.

So you would end up with something like:

wget -qO - http://127.0.0.1/myscript.pl | perl -

For more information on I/O redirection take a look at this:

http://www.tldp.org/LDP/abs/html/io-redirection.html