# Input output (InOut) the file
# usage:
# @array = InOut('read',$file)
# $string = InOut('read',$file)
# InOut('write',$file,\$string)
# InOut('write',$file,\@array)
#$string = "YO!";
#InOut('write','file.txt',\$string);
sub InOut {
my($bit,$file,$data) = @_;
if($bit eq 'read'){
open InOut,"< $file" or die "Cannot open $file for input: $!\n";
my @file = <InOut>;
close InOut;
return wantarray ? @file : join '', @file;
}
if($bit eq 'write'){
open InOut,"> $file" or die "Cannot open $file for output: $!\n";
print InOut ref $data eq 'ARRAY' ? @$data : ref $data eq "SCALAR"? $$data : '';
close InOut;
}
}