2 |
## $Id$ |
## $Id$ |
3 |
## --------------------------------------------------------------------------- |
## --------------------------------------------------------------------------- |
4 |
## $Log$ |
## $Log$ |
5 |
|
## Revision 1.4 2003/05/13 09:23:03 joko |
6 |
|
## pre-flight checks for existance of base directory of to-be-executed script |
7 |
|
## |
8 |
## Revision 1.3 2003/03/31 05:47:01 janosch |
## Revision 1.3 2003/03/31 05:47:01 janosch |
9 |
## Mis mif gex |
## Mis mif gex |
10 |
## |
## |
45 |
|
|
46 |
|
|
47 |
use Data::Dumper; |
use Data::Dumper; |
48 |
|
use File::Basename; |
49 |
|
|
50 |
sub s2f { |
sub s2f { |
51 |
my $filename = shift; |
my $filename = shift; |
52 |
my $string = shift; |
my $string = shift; |
53 |
|
|
54 |
|
# pre-flight checks: Does directory exist? |
55 |
|
my $dirname = dirname($filename); |
56 |
|
if (not -e $dirname) { |
57 |
|
print STDERR __PACKAGE__ . ':' . __LINE__ . ": ERROR: Directory '$dirname' does not exist! (Write attempt)" . "\n"; |
58 |
|
return; |
59 |
|
} |
60 |
|
|
61 |
|
# Perform: File write |
62 |
open(FH, '>' . $filename); |
open(FH, '>' . $filename); |
63 |
print FH $string; |
print FH $string; |
64 |
|
# Always inject ending newline? |
65 |
print FH "\n"; |
print FH "\n"; |
66 |
close(FH); |
close(FH); |
67 |
} |
} |
68 |
|
|
69 |
sub f2s { |
sub f2s { |
70 |
my $filename = shift; |
my $filename = shift; |
71 |
|
|
72 |
|
# pre-flight checks: Does file exist? |
73 |
if (! -e $filename) { |
if (! -e $filename) { |
74 |
print STDERR __PACKAGE__ . ':' . __LINE__ . ": File $filename does not exist!" . "\n"; |
print STDERR __PACKAGE__ . ':' . __LINE__ . ": ERROR: File '$filename' does not exist! (Read attempt)" . "\n"; |
75 |
return; |
return; |
76 |
} |
} |
77 |
|
|
78 |
# read file at once (be careful with big files!!!) |
# read file at once (be careful with big files!!!) |
79 |
open(FH, '<' . $filename); |
open(FH, '<' . $filename); |
80 |
my @buf_arr = <FH>; |
my @buf_arr = <FH>; |