# Copyright 2000 by Stem Systems, Inc. All rights reserved. # If you have this software as part of the prototype release, you are # not allowed to distribute any copies to anyone. This software is not # to shown to anyone else without prior permission from Stem Systems. use strict ; package Stem::Util ; use Carp ; =head1 Stem::Util This file includes two subroutines: read_file and write_file. =cut =head2 read_file read_file is a utility sub to slurp in a file. It returns a list of lines when called in list context. It returns one big string when called in scalar context. =cut # utility sub to slurp in a file. list/scalar context determines either # list of lines or long single string sub read_file { my( $file_name ) = shift ; my( $buf ) ; local( *FH ) ; open( FH, $file_name ) || carp "can't open $file_name $!" ; return if wantarray ; read( FH, $buf, -s FH ) ; return $buf ; # older slow way # local( $/ ) unless wantarray ; # } =head2 write_file write_sub is a utility sub to write a file. It takes a file name and a list of strings. It opens the file and writes all data passed into the file. This will overwrite any data in the file. =cut # utility sub to write a file. takes a file name and a list of strings sub write_file { my( $file_name ) = shift ; local( *FH ) ; open( FH, ">$file_name" ) || carp "can't create $file_name $!" ; print FH @_ ; } =head1 COPYRIGHT Copyright 2000 by Stem Systems, Inc. All rights reserved. If you have this software as part of the prototype release, you are not allowed to distribute any copies to anyone. This software is not to shown to anyone else without prior permission from Stem Systems. =cut 1 ;