W
wana
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
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