in reply to Re^3: PDF output to temp file
in thread PDF output to temp file

The reason why I think system makes more sense than backticks in this example, is, that the usage of backticks implies that the output is used somehow. Think about readability: If we see in a code a backticked expression, where the value is not used, we think that maybe the code is not what the write had expected. If you use system instead, you communicate to the reader more clearly what's going on.

Or, to approach it from a different perspective: Under what conditions would you choose, to use system($cmd) instead of `$cmd`?

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^5: PDF output to temp file
by kcott (Archbishop) on Mar 22, 2012 at 22:17 UTC

    G'day Ronald,

    I think it's possible that we've both slightly misconstrued the other's intent and that this has been exacerbated with each response. I'll address both the general issue of system($cmd) vs. `$cmd` and then look at the more specific case raised by AM.

    In general, I avoid platform-specific code. On the rare occasions when this isn't the case, I'm more likely to choose system($cmd) for exactly the reasons you state: "you communicate to the reader more clearly what's going on". I believe we're in agreement with respect to this general case of usage. If I have a reason not to use system(), I'd normally choose qx{$cmd} over `$cmd`.

    AM's original question contained garbage code. I cobbled together various elements of what he had, to produce something which did what he asked for: temp_1, >>/home/administrator and `evince bill.pdf`; was munged into `evince bill.pdf >> /home/administrator/temp_1`;. I retained the append mode (>>) which he'd used although I'm not convinced that he didn't actually want write mode (>); similarly, I retained the backquotes. I stated that I didn't think he'd described what he really wanted and queried what he was using $rc for.

    -- Ken