in reply to Using backticks with (mount):

This is nothing abnormal - you are checking the wrong variable. You should really check $? before looking at $!.

Please, open your perldocs to perlvar and read

$! If used in a numeric context, yields the current value of errno, with all the usual caveats. (This means that you shouldn't depend on the value of $! to be anything in particular unless you've gotten a specific error return indicating a system error.)
Note the parenthetical part. There is also a long section in perlvar ( under the title Error Indicators ) that may help you out a little.

mikfire

Replies are listed 'Best First'.
RE: Re: Using backticks with (mount):
by BBQ (Curate) on Jul 18, 2000 at 17:02 UTC
    Dude! Great call! And also this, from perlvar:
    Finally, $? may be set to non-0 value if the external program /cdrom/install fails. Upper bits of the particular value may reflect specific error conditions encountered by this program (this is program-dependent), lower-bits reflect mode of failure (segfault, completion, etc.). Note that in contrast to $@, $!, and $^E, which are set only if error condition is detected, the variable $? is set on each wait or pipe close, overwriting the old value.
    But it still doesn't explain why $! would start up with Illegal Seek...

    #!/home/bbq/bin/perl
    # Trust no1!
      Why shouldn't it? The value is indeterminate when no error has occurred. You are seeing, effectively, /dev/random. There is no deeper mystery here, to my understanding.

      mikfire

        No, it isn't random. Yes, you shouldn't depend on it.

        In this case, I'm willing to bet that Perl has code that tries to seek, perhaps to more portably flush buffers. It is perfectly acceptable to try to seek and then see whehter or not it worked in order to tell if you happen to have a file handle to a stream that supports seeking.

        $! actually starts out as zero in a new process (no, I don't think this is guarenteed anywhere) but quickly gets changed when something deep in the guts of some library does something that fails.

        And indeterminate means it could be undef or "Illegal seek" or anything else.

        Well, maybe you're right! Maybe it should... BUT! ;)

        If its called $OS_ERROR, one might expect it to start off undef until some OS errors actually occur. With Illegal Seek, common sense would tell me that OS errors have occured! I guess that's what confuses most people. Indeterminate should be undef, and not Illegal Seek, IMHO.

        #!/home/bbq/bin/perl
        # Trust no1!