| 2 |
## $Id$ |
## $Id$ |
| 3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
| 4 |
## $Log$ |
## $Log$ |
| 5 |
|
## Revision 1.5 2003/06/06 04:00:35 joko |
| 6 |
|
## + binary mode file write |
| 7 |
|
## + don't add a trailing newline always |
| 8 |
|
## |
| 9 |
## Revision 1.4 2003/05/13 09:23:03 joko |
## Revision 1.4 2003/05/13 09:23:03 joko |
| 10 |
## pre-flight checks for existance of base directory of to-be-executed script |
## pre-flight checks for existance of base directory of to-be-executed script |
| 11 |
## |
## |
| 54 |
sub s2f { |
sub s2f { |
| 55 |
my $filename = shift; |
my $filename = shift; |
| 56 |
my $string = shift; |
my $string = shift; |
| 57 |
|
my $args = shift; |
| 58 |
|
|
| 59 |
# pre-flight checks: Does directory exist? |
# pre-flight checks: Does directory exist? |
| 60 |
my $dirname = dirname($filename); |
my $dirname = dirname($filename); |
| 65 |
|
|
| 66 |
# Perform: File write |
# Perform: File write |
| 67 |
open(FH, '>' . $filename); |
open(FH, '>' . $filename); |
| 68 |
|
if ($args->{mode} && $args->{mode} eq 'binary') { |
| 69 |
|
binmode(FH); |
| 70 |
|
} |
| 71 |
print FH $string; |
print FH $string; |
| 72 |
# Always inject ending newline? |
# Always inject ending newline? No, since it unneccessarily |
| 73 |
print FH "\n"; |
# modifies files with absolutely *no* changes in content. |
| 74 |
|
print FH "\n" if $string !~ /\n$/; |
| 75 |
close(FH); |
close(FH); |
| 76 |
} |
} |
| 77 |
|
|