Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


In reply to curl without backticks and system() by urbansumo

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (2)
    As of 2019-12-08 10:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?