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

Re: Set difference between sets of files



On May 5,  7:54pm, Peter Stephenson wrote:
} Subject: Re: Set difference between sets of files
}
} On Tue, 05 May 2009 11:00:10 -0700
} Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
} > typeset -A differ
} > eval differ\[${(q)^MASTER_FILES}\]=a
} > eval differ\[${(q)^BACKUP_FILES}\]=b
} > print -l -- ${(k)differ[(R)a]}
} 
} I was trying to come up with something that "just works", which is
} difficult if you're manipulating variable substitution and usually ends
} up looking like a bus smash.

Thd following is arcane, but seems to do the trick:

MASTER_FILES=('a[b' '$cd' 'ef}' 'g h' 1 2 3)
BACKUP_FILES=('a[b' '$cd' 'ef}')

typeset -A differ
eval 'differ[${:-'${(q)^BACKUP_FILES}'}]=b'
eval 'differ[${:-'${(q)^MASTER_FILES}'}]=a'
print -l -- ${(k)differ[(R)b]}

I still can't get the "unset" approach to work.  (Note I had the order
of operations reversed in my original example, it's the backup less the
master that's wanted in this case.)

The above came from the epiphany that the (shorter to type but longer
to execute)

for f in $BACKUP_FILES; differ[$f]=b
for f in $MASTER_FILES; differ[$f]=a

works fine, merely requiring an additional local "f".  So the trick is
to force parameter substitution, thereby subverting the subscript magic
almost-but-not-quite double-quoting.

} ("Bus smash" may be British slang; it indicates ugliness.)

I got the ugliness, but if that's rhyming slang I haven't managed to
un-rhyme it.



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