http://qs1969.pair.com?node_id=811370

benizi has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, long time no see. I've been off in the desert of .NET, but daily perl from the commandline still sustained me.

Long ago I got into the habit of keeping my iteratively-developed Perl scripts as comments in the files that they generate. For example, I hate that the default X11 Compose maps force a specific order for adding accents (letter + accent), whereas I often find myself wanting the opposite (accent + letter). That way I can type either <Multi_Key> <e> <'> or <Multi_Key> <'> <e> to get é. So, now my ~/.XCompose-ordering contains the following comment: (In the file it's on one line, here split for slight readability)

# perl -lanwe ' BEGIN { push @{$o{0+@$_}}, $_ for map [split//], qw/021 0132 0213 0231 + 0312 0321/; } next unless /LATIN.*LETTER...WITH/; next if /<dead/; my @keys = @F[0..(-1+(grep $F[$_] eq ":", 0..$#F)[0])]; $K=join"-",sort @keys; next if $seen{$K}; $seen{$K}++; next if $K eq "<Multi_key>-<U>-<o>"; next if /LETTER \S+ WITH \S+ AND \S+/; print "@keys[@$_] @F[@keys..$#F]" for @{$o{0+@keys}} ' /usr/share/X11/locale/${LANG}/Compose

I was wondering if any monks had clever ways to execute this code to regenerate the file while keeping the code itself as a comment in the file (using perl -x for example). Currently, I've been using the following Zsh snippet:

file=~/.XCompose-ordering line=$(head -n 1 $file) (print -lr $line ; eval ${line[3,-1]}) > $file

But it'd be much cooler to just do perl -x ~/.XCompose-ordering or even ~/.XCompose-ordering.