"
#!perl -i.bak
@ARGV = ($0);
while (<>) {
$end = 1 if /^__END__/;
print if $end < 2;
$end++ if /^"/ and $end;
if (eof) {
open my $f, "</usr/share/X11/locale/$ENV{LANG}/Compose" or die
+ "<$!";
print for <$f>; # manipulate the line here
close $f;
}
}
__END__
"
# normal lines start here
# etc. etc.
But I suspect this is just a consequence of .XCompose files just ignoring ill-formed lines. (and not because it accepts multi-line strings -- note that I embedded several double-quotes.)
Another interesting approach I tried was to simply add the following header:
#!/bin/env updater
# perl -lanwe '(...the script from before...)' inputfile
# ...
# the normal output...
# ...
~/bin/updater was:
#!/usr/bin/perl
use strict;
use warnings;
my $script = '';
my $out = '';
my ($file) = @ARGV;
while (<>) {
next unless s/^(#\s*)//;
$script .= $_ unless $. == 1;
$out .= "$1$_";
}
open STDOUT, '>', $file;
print $out;
open my $pipe, "| $ENV{SHELL}";
print $pipe $script;
close $pipe;
(NB. this doesn't make a backup like the other way.) That way, I can make .XCompose-ordering itself executable, and then simply run it to regenerate it. But, it has the advantage that it works for any file format that uses '#' comments. |