Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

comment on

( [id://3333] : superdoc . print w/replies, xml ) Need Help??
You ask about redirecting STDOUT and STDERR for system calls given as lists. A good way to do this is with the module IPC::Run.
use IPC::Run qw( run ) ; run \@cmd, \$in, \$out, \$err;

One idea you might be able to use for parameterizing your error messages for various commands would be to pass in a hash reference containing explanatory messages indexed by return codes. Also see perlvar for how you can use the variable $! to obtain error message strings after a failed system call.

Finally, the reason spelled-out file handles are considered "bad style" compared to IO::File is that they create global names, which might conflict with other modules. IO::File uses unique private symbols instead.

In reply to Re^3: First Unix Admin Script - Request for Constructive Critisism by tall_man
in thread First Unix Admin Script - Request for Constructive Critisism by D.Millin

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.