Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Style question: Can this be written in a more elegant way?



On Apr 24, 10:27am, Marc Chantreux wrote:
}
} Here is mine but i'm sure there is faster.
} 
} file=( *(om) )
} ((  $file[1] )) && PROG_SUCCESS || PROG_FAIL

I think you mean:

    file=( X*(Nom[1]) )
    (( $+file )) && PROG_SUCCESS $file || PROG_FAIL

However, that will run PROG_FAIL if PROG_SUCCESS fails, as well as if
there are no matching files.  I don't think you can avoid if/else.

    if (( $+file )); then PROG_SUCCESS $file; else PROG_FAIL; fi

Note that in the event that there are two or more files with the same
time stamp, there's no guarantee which one of them is chosen, and in
fact X*(om[1]) and X*(Om[1]) might both choose the same file.



Messages sorted by: Reverse Date, Date, Thread, Author