in reply to Re: system function is returning status -1 when running a unix command
in thread system function is returning status -1 when running a unix command

ikegami, could you please explain what is going on here:
> perl -wle ' $SIG{CHLD}="IGNORE"; $! = 33; print system("ls -d ."); print -+-$!; print $!; print -+-$!' . -1 33 No child processes 10

It seems that string-ifying "$!" changes its value.

Replies are listed 'Best First'.
Re^3: system function is returning status -1 when running a unix command
by ikegami (Patriarch) on Apr 08, 2009 at 18:37 UTC

    print can result in system calls. $! is meaningless after the first print.

    $ perl -wle' $SIG{CHLD}="IGNORE"; $! = 0; my $rv = system("ls -d ."); my $errno = $!; print $rv; print 0+$errno; print $errno; print 0+$errno; ' . -1 10 No child processes 10

    Note that 0+ is much easier to understand than -+-, and it conveys the intent much better.