http://www.perlmonks.org?node_id=1180561

urbansumo has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

Someone told me that I should avoid using backticks and system() in my scripts. I therefore come to the gates with a couple of questions:

1. Is using backticks and/or system() really that bad, ie is it ever appropriate to use backticks and what security issues does it pose if you do, or is it just considered sloppy (ie not purist) programming?

2. My specific requirement is the use of curl in order to pull out the latest wordpress version from the header information, for example:

our $response = `curl -sILk wordpress.org/latest | grep Content-Dispos +ition`;
Here is what the $response variable would look like:
Content-Disposition: attachment; filename=wordpress-4.7.2.tar.gz

This response variable is then passed through a regex filter to return the version number only (4.7.2).

Here is the full subroutine in all its glory:

sub get_latest_wordpress_version { our $url = "https://wordpress.org/latest"; our $response = `curl -sILk wordpress.org/latest | grep Conten +t-Disposition`; our ($wp_latest_version) = $response =~ /(\d+.\d+(.\d+)?)/; return $wp_latest_version; }

This works perfectly, however, I'm looking for a way to not have to run system commands to achieve this, but the kicker is, I'm looking to achieve this using only core perl modules, to ensure maximum portability of the code.

I've done a lot of searching for ways to achieve this but hit roadblocks that mean the backticks are here to stay for a while.

Any help you can provide will be gratefully received.

Urbansumo