Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Best way to keep script with generated output

by ikegami (Patriarch)
on Dec 07, 2009 at 07:39 UTC ( #811435=note: print w/replies, xml ) Need Help??


in reply to Best way to keep script with generated output

What's the format of .XCompose-ordering? Is it a sh script?

Replies are listed 'Best First'.
Re^2: Best way to keep script with generated output
by benizi (Hermit) on Dec 07, 2009 at 08:09 UTC

    .XCompose-ordering has the same format as .XCompose. (I include the former from the latter.) It consists of lines of usually the following format:

    <XKeySym>(?: <XKeySym>)* : (?:"string"|U[\da-fA-F]{4})(?: description)?

    String is usually a single UTF-8 char, but is a C-style string (\n \r \\, etc.). And Uxxxx represents a single Unicode char. The format also supports '#'-comments, which last to the end of the line, ala perl. And it supports 'include' lines:

    include "other file"

    Full specs

      Can you include a literal newline inside the double quotes? That would allow you to use perl -x:
      <not> <gonna> <happen> : " #!perl . . This is the script . __END__ " . . This is the actual file .

      So what would the script look like? How about

      local $^I = '~'; local @ARGV = __FILE__; my $seen_data; while (<>) { if (!$seen_data) { $seen_data = $_ eq qq{__END__\n}; next; } ... change $_ as desired ... } continue { print; }

        Huh. Cool. Yeah, that would work (via perl -x ~/.XCompose-ordering). Apparently there aren't any ill effects from even adding the following to .XCompose-ordering:

        " #!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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://811435]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2022-09-29 11:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (125 votes). Check out past polls.

    Notices?