NAME
File::Reader - Perl extension for Read and write easily text file
SYNOPSIS
use File::Reader qw( Write Read ReadConf ReWrite );
@myArray = Read('/home/arnaud/.bashrc');
@mysArray = sRead('/home/arnaud/.bashrc',1,2);
$file = '/home/arnaud/write_by_Battosai' ;
$message = "Something to write\n" ;
Write($file, $message) ;
@message=("something", "to", "write", "\n");
Write($file, @message) ;
sWrite($file,"Something to write\n",1,2) ;
%conf_file = ReadConf('/etc/file.conf') ;
DESCRIPTION
Write :
Write(file_to_write, data_to_write) : this function write somme data in a file. You can call it like that : Write($file, @data) ;
Read :
Read("file_to_read") : read all data in "file_to_read". IMPORTANT file is read just as it is ! Don't forget to treat data incomming :-). Read() return undef if the file that you try to open does not exist.
ReWrite :
ReWrite(file_to_write, data_to_write) : write data in the end of "file_to_write". If file does not exist ReWrite() create him. The function don't erase the original file. To really re-write a file (erase and write it) use Write().
ReadConf :
ReadConf("some_configuration_file") : Read a configuration (wich is write like : key = value) and return a hash (usable by : $conf{key}). ReadConf() return undef if the file that you try to read does not exist.
ReadConf2 :
ReadConf2("some_configuration_file","separator") : same as ReadConf() but you can specify the separator to use in the configuration file.
configuration file :
key1 :: value1
key2 :: value2
usable with the code :
%conf = ReadConf2("configuration_file",'::') ;
print "$conf{key1}\n" ;
ReadConfAdv :
ReadConfAdv($conf_fln,$conf_start,$conf_stop) : with this function you can use only one configuration file for several applications by putting separating beacons of section.
Ex : %conf = ReadConfAdv("conf_file",'<start-tag>','<stop-tag>') ;
work with a configuration file like :
<start-tag>
key1 = value1
key2 = value2
<stop-tag>
[other-start]
key3 = value3
[other-stop]
ReadConfAdv2 :
ReadConfAdv2($conf_fln,$conf_start,$conf_stop,$level,$sep) : same options that ReadConfAdv() but you can specify, moreover, the separator of the pairs of keys/values in the configuration file (like ReadConf2() ).
listRep :
listRep("any_directory/" : return a table containing the contents of "any_directory/"
Ex : @dir = listRep("/etc/") ;
The following function (s*) are the "secure" version of previous functions. They make somes tests one files before reading and writing them.
sReWrite :
sReWrite($name,$data,$warning) : if you set $warning to 1 (default) File::Reader print test on STDERR. If $warning = 0, STDERR is redirect to file_reader_err.log.
sWrite :
sWrite($name,$data,$warning) : same as sReWrite() but with Write() functionnality.
sRead :
sRead($name,$warning,$level) : see sReWrite() for explanations relating to $warning. $level can take severals values :
0 : (welcome hackers !) No real security on the $name variable
1 : (Medium security) All the escape shell caracters are escaped (&|; etc.)
2 : (paranoid) All the escape shell caracters are delete !
If you use File::Reader in CGI it's strongly recommend to use the lvl 2.
Default is 1
sReadConf :
sReadConf($conf_fln,$level) : see above for explanations relating to $level
sReadConfAdv :
sReadConfAdv($conf_fln,$conf_start,$conf_stop,$level) : see above for explanations relating to $level, $conf_start and $conf_stop
sReadConf2
sReadConf2($conf_fln,$level,$sep) : see above for explanations relating to $level and $sep
sReadConfAdv2
sReadConfAdv2($conf_fln,$conf_start,$conf_stop,$level,$sep) : see above for explanations relating to $conf_start, $conf_stop, $level and $sep
EXPORT
None by default.
use File::Reader qw ( sWrite sReadConf ) ; # Export the two functions sWrite() and sReadConf().
COMPATIBILITY
You can assume the compatibility with the old syntax of Battosai by :
use File::Reader qw ( ecrire ouvre reecrire lireConfAdv lireConf listRep listDir sReecrire sOuvre sLireConf sLireConfAdv lireConfAdv2 sLireConf2 sLireConfAdv2 lireConf2 ) ;
But this method is deprecated. Moreover new function will never profit from binding for old syntax. Moreover old syntax could be less powerful than the news.
AUTHOR
Arnaud DUPUIS, <arno@asocial.org>
COPYRIGHT AND LICENCE
Copyright (c) 2004 Arnaud DUPUIS <arno@asocial.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.