File: encode_append.pl

package info (click to toggle)
libpar-packer-perl 0.978-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,324 kB
  • ctags: 494
  • sloc: perl: 19,945; ansic: 904; makefile: 64
file content (36 lines) | stat: -rw-r--r-- 820 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use strict;
use warnings;
# Used in myldr/Makefile.PL / myldr/Makefile.
# This script appends the uuencoded contents of $ARGV[0] to the file
# specified as $ARGV[1] as __DATA__ section. Any previous _DATA_ is replaced.
# section.
#
# 2006, Steffen Mueller

$/ = undef;

my $usage = <<HERE;
Usage: $0 FILE-TO-ENCODE FILE-TO-APPEND-TO
HERE

my $infile = shift @ARGV;
die $usage if not defined $infile or not -f $infile;

my $outfile = shift @ARGV;
die $usage if not defined $outfile or not -f $outfile;

open my $fh, '<', $outfile or die $!;
binmode $fh;
my $contents = <$fh>;
close $fh;
$contents =~ s/^__DATA__\r?\n.*\z//ms;

open my $ih, '<', $infile or die $!;
binmode $ih;
open $fh, '>', $outfile or die $!;
binmode $fh;
print $fh $contents;
print $fh "\n__DATA__\n";
print $fh pack 'u', <$ih>;
close $ih;
close $fh;