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

Re: Getting rid of temporaries...



On Sep 10, 10:34pm, DervishD wrote:
} Subject: Getting rid of temporaries...
}
}     I have a directory structure containing files whose names match
} the expression '*.??.jpg'.
} [...] I want to strip the number and the '.jpg' suffix from the names.

}     Now the question: how can I do this without using the temporary
} parameter 'array' and, if possible, without 'uniq'.

If you have the array, it's easy to do without uniq.  To do it without
the array begins to creep into the realm of "so difficult it's not
worth bothering."

The 'e' globbing flag gets you most of the way:

    print -l *.??.jpg(e['REPLY=${REPLY%.??.jpg}'])

Of course, that uses the magic temporary $REPLY variable, so it hasn't
really eliminated temporaries.

On Sep 10,  3:38pm, Danek Duvall wrote:
}
}     typeset -U array
}     array=( /directory/*/* )
}     array=( ${^array%.<00-99>.jpg} )
}     print -l $array

This suggestion is on the right track, but it's not equivalent to Raul's
original one, because your first assignment may match names that do not
match *.<00-99>.jpg, which won't be modified by the second assignment.

} will do what you want.  The "typeset -U" makes $array discard duplicate
} elements, but that requires the reassignment once the dups are gone

I'm not sure what you mean by "requires the reassignment once the dups
are gone".  You have to strip the suffixes before zsh can tell what the
duplicates are.

} though it might be a nice candidate for yet another parameter expansion
} flag.  :)

You mean like ${(u)...}, which is in 4.1.1-dev-* ...
 
} The "^" turns on rcexpandparam for the expansion of $array, which means
} that, as an array, each element is modified.

That's not what rcexpandparam means.  It means that, if the expansion is
concatenated with other strings before and/or behind, then every element
is individually so concatenated.  You don't have any concatenation going
on here, so the caret isn't needed.

So we end up with, perhaps:

    typeset -U array
    array=( *.<00-99>.jpg(e['REPLY=${REPLY%.??.jpg}']) )
    print -l $array



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