6 |
use File::Path qw//; |
use File::Path qw//; |
7 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
8 |
|
|
9 |
my $debug = 1; |
my $debug = 0; |
10 |
|
|
11 |
sub mkpath { |
sub mkpath { |
12 |
my $file = shift; |
my $file = shift; |
39 |
# $content =~ s{[\n\r]*$}{\n}s; |
# $content =~ s{[\n\r]*$}{\n}s; |
40 |
|
|
41 |
if ( $on_disk =~ s{([\s+]exit[\s\d]*)$}{\n$content\n$1}s ) { |
if ( $on_disk =~ s{([\s+]exit[\s\d]*)$}{\n$content\n$1}s ) { |
42 |
# warn "# insert $file\n$on_disk"; |
warn "# insert $file\n$on_disk" if $debug; |
43 |
write_file $file, $on_disk; |
write_file $file, $on_disk; |
44 |
} else { |
} else { |
45 |
# warn "# append $file\n$content\n"; |
warn "# append $file\n$content\n" if $debug; |
46 |
open($fh, '>>', $file); |
open($fh, '>>', $file); |
47 |
print $fh $content; |
print $fh $content; |
48 |
close($fh); |
close($fh); |
49 |
} |
} |
50 |
|
|
51 |
carp "## append to $file"; |
carp "## append to $file" if $debug; |
52 |
return -s $file; |
return -s $file; |
53 |
|
} else { |
54 |
|
warn "## $file not modified" if $debug; |
55 |
} |
} |
56 |
} |
} |
57 |
|
|