Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^4: Best way to keep script with generated output

by benizi (Hermit)
on Dec 09, 2009 at 03:10 UTC ( #811856=note: print w/replies, xml ) Need Help??


in reply to Re^3: Best way to keep script with generated output
in thread Best way to keep script with generated output

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.

Replies are listed 'Best First'.
Re^5: Best way to keep script with generated output
by ikegami (Patriarch) on Dec 09, 2009 at 17:48 UTC
    But then you need to hardcode your own name into the file. I specifically avoided doing that. It's your call if that matters to you.

      I don't follow. What name am I hard-coding? The "/usr/share/X11/locale/$ENV{LANG}/Compose" file is an input to the script. It's not the file being generated (~/.XCompose-ordering). I don't see what else is hard-coded.

        I'm referring to inputfile
        I'm referring to inputfile

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2022-08-17 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?