No, system calls are NOT calls to
system. Calls to
system don't set $!, they set $?. System calls are function calls that interact with the system, and typically have an obvious 1-1 mapping to your systems library calls that set
errno. That's C/Unix speak, but to fully understand Perl, you must understand C and Unix, as large parts of Perl are designed to work with Unix.
Functions that set $! will always return a false value on failure, and a true value on success. Never, ever use $! to determine whether something succeeded or not - the specification of your system libraries allows a function to set errno to whatever it wants in case of success (all that $! does is give you the value of errno - whose value usually isn't under Perls control). Always use the return value of the function used to determine success, and only use $! immediately after determining failure. Typically this is done by interpolating $! in the message you give with die. In your example, both print and open can set $!. But if your code reaches the test for if ($!), the open has succeeded (because you'll die if it fails). Which means that at that moment, the value of $! is utterly meaningless. No information can be derived from it.
The manual page will tell you whether a function sets $!. Functions that set $! include (but aren't limited to): open, close, print, umask, chmod, unlink, rename, mkdir, rmdir, sysopen, sysread, syswrite, and fork.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.