AtomicSoft.com Add power to your website!
Home Products Services Support Free
EasyData/SQL
easy-to-use web interface for SQL databases with countless features
AtomicDesk
help desk, FAQ, knowledge base, live support chat - all in one product
Custom programming
Installation
Documentation
HelpDesk
Libraries
Join our newsletter for information on software updates and new releases. You may unsubscribe at any time.



Click here to download plain text source code.

# subroutine name: readdata
# Reads all data from datafile
# If error occurs (e.g. file doesn't exist), makes CGI process exit with error
# Returns: reference to the array of lines, trailing "\n" in each
#          line is not removed
# Global variables used:
#    $no_flock - disable flock or not
sub readdata {
    my($datafile) = @_;
    my @data;
    # If OS (like Win95) desn't support flock, we have to
    # go unreliable and slow way and create "lock" file
    GetFileLock("$datafile.lock");
    local *DATA;
    if (open(DATA,"<$datafile")) {
        # shared locking
        flock(DATA, 1) unless ($no_flock);
        my $line;
        while ($line = <DATA>) {
            push (@data, $line);
        };
        # unlock file
        flock(DATA, 8) unless ($no_flock);
        close(DATA);
        ReleaseFileLock("$datafile.lock");
    } else {
          ReleaseFileLock("$datafile.lock");
        die("Error in subroutine readdata: Can't open $datafile. Reason: $!");
    };
    return \@data;
}
 
Copyright © 1999-2007 Atomicsoft Ltd. All Rights Reserved.