#This file is copyright of Web Orientated Technologies Ltd. and may not be copied, duplicated or modified without the permission of Web Orientated Technologies Ltd. sub read_dir { #returns files in directory if OK # -1 no directory # my ($directory,$exclude)=@_; my (@out) = (); if (!(-d $directory)) { $out[0] = -1; } else { opendir (xx_dh_xx, $directory); if ($exclude == 1) { @out = grep {!/^\./} (readdir (xx_dh_xx)); } else { @out = readdir (xx_dh_xx); } closedir (xx_dh_xx); } return (sort(@out)); } sub write_to_file { #returns 0 if OK # -1 can't write to file # my ($file, $content) = @_; my ($out) = 0; use Fcntl ':flock'; unless (open (xx_my_xx_fh, "> ".$file)) { $out = -1; return ($out); exit (-1); } flock (xx_my_xx_fh, LOCK_EX); print xx_my_xx_fh $content; flock (xx_my_xx_fh, LOCK_UN); close (xx_my_xx_fh); return ($out); } sub read_from_file { #returns array of content of file # -1 can't read file # my ($file) = @_; my (@out) = (); use Fcntl ':flock'; unless (open (xx_my_xxx_fh, "< ".$file)) { $out = -1; return ($out[0]); exit (-1); } flock (xx_my_xxx_fh, LOCK_EX); @out = ; flock (xx_my_xxx_fh, LOCK_UN); close (xx_my_xxx_fh); return (@out); } 1;