Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 46267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T15:56:21+00:00 2026-05-10T15:56:21+00:00

Many beginning programmers write code like this: sub copy_file ($$) { my $from =

  • 0

Many beginning programmers write code like this:

sub copy_file ($$) {   my $from = shift;   my $to = shift;    `cp $from $to`; } 

Is this bad, and why? Should backticks ever be used? If so, how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T15:56:22+00:00Added an answer on May 10, 2026 at 3:56 pm

    A few people have already mentioned that you should only use backticks when:

    • You need to capture (or supress) the output.
    • There exists no built-in function or Perl module to do the same task, or you have a good reason not to use the module or built-in.
    • You sanitise your input.
    • You check the return value.

    Unfortunately, things like checking the return value properly can be quite challenging. Did it die to a signal? Did it run to completion, but return a funny exit status? The standard ways of trying to interpret $? are just awful.

    I’d recommend using the IPC::System::Simple module’s capture() and system() functions rather than backticks. The capture() function works just like backticks, except that:

    • It provides detailed diagnostics if the command doesn’t start, is killed by a signal, or returns an unexpected exit value.
    • It provides detailed diagnostics if passed tainted data.
    • It provides an easy mechanism for specifying acceptable exit values.
    • It allows you to call backticks without the shell, if you want to.
    • It provides reliable mechanisms for avoiding the shell, even if you use a single argument.

    The commands also work consistently across operating systems and Perl versions, unlike Perl’s built-in system() which may not check for tainted data when called with multiple arguments on older versions of Perl (eg, 5.6.0 with multiple arguments), or which may call the shell anyway under Windows.

    As an example, the following code snippet will save the results of a call to perldoc into a scalar, avoids the shell, and throws an exception if the page cannot be found (since perldoc returns 1).

    #!/usr/bin/perl -w use strict; use IPC::System::Simple qw(capture);  # Make sure we're called with command-line arguments. @ARGV or die 'Usage: $0 arguments\n';  my $documentation = capture('perldoc', @ARGV); 

    IPC::System::Simple is pure Perl, works on 5.6.0 and above, and doesn’t have any dependencies that wouldn’t normally come with your Perl distribution. (On Windows it depends upon a Win32:: module that comes with both ActiveState and Strawberry Perl).

    Disclaimer: I’m the author of IPC::System::Simple, so I may show some bias.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 63k
  • Answers 63k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The easiest way to go about it in Silverlight 2.0… May 11, 2026 at 10:29 am
  • added an answer Yes, it is still very relevant and an excellent resource. May 11, 2026 at 10:29 am
  • added an answer If you are going to install the XP on your… May 11, 2026 at 10:29 am

Related Questions

Many beginning programmers write code like this: sub copy_file ($$) { my $from =
I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR
Many times I have seen Visual Studio solutions which have multiple projects that share
Many times we find ourselves working on a problem, only to figure out the
Many frameworks seek to abstract away from HTML (custom tags, JSFs component system) in
Many applications have grids that display data from a database table one page at
Many people use Mock Objects when they are writing unit tests. What is a
Many of us have used Perfmon tool to do performance analysis. Especially with .Net
Many websites, including this one, add what are apparently called slugs - descriptive but
Many of the parameters for interacting with the Office Object model in VSTO require

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.