I have seen, in the dim and distant path, text files distributed in the form of a shell script that creates all the files. I'd like to do that in a perl script, so here's my first attempt. This is designed to work on minimal Win32 installations and other platforms, which is why it's wrapped in NT DOS batch language.

Oh, nearly forgot, you might need to fix your Perl installation so that it globs file names. See perldoc perlwin32 and implement the Wild.pm module.

One thing it can't do is include it's own offspring, because of the END_UNLIKELY used as a PRINT terminator. That's unlikely to be a requirement, though. Also make sure that the file you redirect the output to somewhere else so that isn't picked up by the script itself!

@rem = '--*-Perl-*-- @echo off perl "%~dpnx0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl @rem '; #!perl #line 8 use strict; print "\@rem = '--*-Perl-*--\n"; print "\@echo off\n"; print "perl \"%~dpnx0\" %1 %2 %3 %4 %5 %6 %7 %8 %9\n"; print "goto end_of_perl\n"; print "\@rem ';\n"; print "#!perl\n"; print "#line 8\n"; my @files=@ARGV; for my $file (@files) { open(INFILE, '<', $file); print "open (STDOUT, '>', \"$file\");\n"; print "print <<'EOT_UNLIKELY';\n"; while (<INFILE>) { die "Found EOT" if /^EOT_UNLIKELY/; print; } print "EOT_UNLIKELY\n"; } print "__END__\n"; print ":end_of_perl\n"; __END__ :endofperl

Replies are listed 'Best First'.
Re: Packaging files in a perl script
by belg4mit (Prior) on Aug 15, 2003 at 15:01 UTC
    par (note the case).

    --
    I'm not belgian but I play one on TV.

      They do say that X% of any Perl program has already been written (add value of X to taste, 80% of all statistics are just made up on the spot anyway), but it seems that 100% of this has already been done. Oh well, it only took me 10 minutes to write it, and I learned a little while I was at it (I'd never used print << before - it was actually rather hard to find the docs for this feature, it isn't mentioned under the print command).

      I'm also enjoying Perl more and more all the time.