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

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



Hi Bart,


} file=( *(om) )
} ((  $file[1] )) && PROG_SUCCESS || PROG_FAIL

I think you mean:

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

I didn't : my lines was the best i've found.
- haven't thought about the N modifier
- I've tried something like *(om)[1,2] but it naturally failed. didn't found the ([x]) in the doc.

but now i'll do mean!

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

i have noticed that a lot of people here don't use the alternative form. is there a reason to not use the next line ?

if (( $+file )) { PROG_SUCCESS $file } else { PROG_FAIL }

BTW, i've tried another way to launch PROG_SUCCESS for the first file but it failed because it execute the e:: code for all the files. Peraps there is a trick i missed?

% ls
is  score  the  this
% : *(Nom[1]e:echo last file $REPLY:)
last file score
last file score
last file score
last file score


regards
mc



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