129 |
|
|
130 |
sub suck_file { |
sub suck_file { |
131 |
my $file = shift || croak "suck_file called without argument"; |
my $file = shift || croak "suck_file called without argument"; |
132 |
open(H,$file) || die "can't open '$file': $!"; |
if (! -f $file) { |
133 |
|
my $template_file = $file; |
134 |
|
$template_file =~ s,^.*?/*([^/]+)$,$1,; |
135 |
|
if (-f $template_file) { |
136 |
|
print "WARNING: can't find '$file', copy template '$template_file' ? [Y/n]: "; |
137 |
|
my $a = <STDIN>; |
138 |
|
chomp $a; |
139 |
|
if ($a =~ m/^y/i || $a eq "") { |
140 |
|
open(I,$template_file) || die "FATAL: can't open template file '$template_file': $!"; |
141 |
|
open(O,"> $file") || die "FATAL: can't create '$file' from template: $!"; |
142 |
|
while(<I>) { |
143 |
|
print O $_; |
144 |
|
} |
145 |
|
close(I); |
146 |
|
close(O); |
147 |
|
print "File '$file' created from template '$template_file'\n"; |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
} |
152 |
|
|
153 |
|
if (! -f $file) { |
154 |
|
print STDERR "FATAL: please create file $file and then re-run this script!\n"; |
155 |
|
exit 1; |
156 |
|
} |
157 |
|
|
158 |
|
open(H,$file) || die "FATAL: can't open '$file': $!"; |
159 |
my $content; |
my $content; |
160 |
while (<H>) { $content .= $_; } ; |
while (<H>) { $content .= $_; } ; |
161 |
close(H); |
close(H); |