Hi Everyone,

I haven't much experience writting Perl code on Unix, as the company where I work as a Unix administrator only uses the Korn shell, Awk and Sed for everything. For my current project, I have to use Perl :-).As I have never seen or used perl in a system admin role on Unix, I haven't developed my own style. I would value the monks advise on the user of system() and programming style.

In my scripts I need to deport and import volume manger disk groups in order to take a point-in-time copy. Each command must be check to ensure that I get clean copy of the disk group. If I were using the Korn Shell, when I need to check the return code, the code would look something like:

vxdg deport oracle if [ $? ] then echo "Could not deport oracle" exit 1 fi

From digging through the Camel book and perldocs, I read that when executing a command using the system function, $? needs to be shifted by eight bytes to get the proper return code. From searching the net, I have seen this implemented in a variety different way, such as:

system ("vxdg deport oracle"); if ($?){ $rc = $_ >> 8; print "Could not deport oracle"; exit 1; }

What I am unsure about is what is then best/efficient way of implementing this. Is it better to carry out the $rc = $_ >> 8; operation after every system call and then check the return code, or would it be better to encase system within the if statement?, and only do the $rc = $_ >> 8; where I absolutely need to use the proper return code.

Thanks,
Darren

In reply to System and a question of style by D.Millin

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, details, 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, summary, 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.