You're viewing a comment by waldner and its responses.

waldner Permalink
November 03, 2008, 11:55

@Marco R:

Awk's logic is not broken. I just follows the C (and many other languages) model, where any nonzero value is considered true, so you can do
"if <something> then ...".

The shell uses the same logic, but it just uses zero to indicate success and nonzero to indicate failure, but that's not necessarily a bad thing.

In the particular application of validating an address, the return value depends on the context you'll use that. If the function ok() is to be invoked within the awk program only, then I think returning 1 for success makes sense (and perhaps return 0 at the end of the overall awk program if it succeeded in its entirety). If, on the other hand, you want to use the awk program directly from the shell, only to check IP addresses, then you can return 0 for success, as you suggest. I think it's a matter of personal taste after all.

Regarding the function ok() you suggest, something similar was proposed by another reader (see previous comments). However, I don't see the point in returning "1==0" instead of simply 0.

Thanks for your comment!

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "antispam_100": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.