system return value makes for strange logic

From: wana (ioneabu_at_yahoo.com)
Date: 10/29/04


Date: Fri, 29 Oct 2004 11:25:35 -0400

I was writing a short script to create a mysql database and kept getting
confusing results:

system("mysqladmin --user='$user' --password='$pass' create $db")
        or die "$db not created due to error\n";

The function lead to die being called and printing the error message but the
database was being created successfully. I changed it to:

system("mysqladmin --user='$user' --password='$pass' create $db")
        and die "$db not created due to error\n";

and even though it doesn't look right at first glance, it makes sense
because system apparently returns 0 with success and numbers > 0 for
failure. I read about it in 'Programming Perl' and saw the explanation
that the return value gives information about the nature of the failure.
Isn't this strange? Don't we normally look to $! for errors and consider 0
to mean failure? I can accept it, but 'do and die' sounds funny compared
to the usual 'do or die'.

wana



Relevant Pages

  • Re: IC: Wolves Glen Pub
    ... wolf - and the wolf outline in the mirror has shifted to clamp down on ... Die 1 yielded 8 - a success ... Die 2 yielded 2 - a failure ...
    (rec.games.frp.storyteller)
  • Re: IC: Wolves Glen Pub
    ... Jack raises an eyebrow at this, ... Die 2 yielded 9 - a success ... Die 6 yielded 3 - a failure ...
    (rec.games.frp.storyteller)
  • Re: Image Handling
    ... and have their location put into a MySQL database? ... I know that this is really basic but so are my PHP skills at the moment. ... or die ); ...
    (comp.lang.php)
  • Re: IC: Wolves Glen Pub
    ... ((OOC: Found some free wi-fi at a local coffeeshop, ... The Mind would pick up that when Jack drew his fingers across ... Die 1 yielded 7 - a success ...
    (rec.games.frp.storyteller)
  • Re: Question for geneticists: Aging
    ... individual reproductive success under different conditions. ... lived animals are under high predation pressure. ... they die straight afterwards leave more descendants than ones who ... So mice and rabbits reproduce quickly and often and I would ...
    (talk.origins)