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,In reply to System and a question of style by D.Millin
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |