--- nfo/perl/libs/shortcuts/files.pm 2003/05/13 09:23:03 1.4 +++ nfo/perl/libs/shortcuts/files.pm 2003/06/06 04:00:35 1.5 @@ -1,7 +1,11 @@ ## --------------------------------------------------------------------------- -## $Id: files.pm,v 1.4 2003/05/13 09:23:03 joko Exp $ +## $Id: files.pm,v 1.5 2003/06/06 04:00:35 joko Exp $ ## --------------------------------------------------------------------------- ## $Log: files.pm,v $ +## Revision 1.5 2003/06/06 04:00:35 joko +## + binary mode file write +## + don't add a trailing newline always +## ## Revision 1.4 2003/05/13 09:23:03 joko ## pre-flight checks for existance of base directory of to-be-executed script ## @@ -50,6 +54,7 @@ sub s2f { my $filename = shift; my $string = shift; + my $args = shift; # pre-flight checks: Does directory exist? my $dirname = dirname($filename); @@ -60,9 +65,13 @@ # Perform: File write open(FH, '>' . $filename); + if ($args->{mode} && $args->{mode} eq 'binary') { + binmode(FH); + } print FH $string; - # Always inject ending newline? - print FH "\n"; + # Always inject ending newline? No, since it unneccessarily + # modifies files with absolutely *no* changes in content. + print FH "\n" if $string !~ /\n$/; close(FH); }