Reads DBM file, printing entries with tie and untie function : DBM « Database « Perl






Reads DBM file, printing entries with tie and untie function

   

#!/usr/bin/perl -w

# Usage:
#  Perl readDB.pl database

use SDBM_File;
use Fcntl;

# Print format for STDOUT.
format STDOUT=
@<<<<<<<<<<<<<<<<<<  @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$key, $value  
.

$database  = $ARGV[0];

$mode = 0666;

$flags =  O_RDONLY | binary(); 

tie(%execs, 'SDBM_File', $database, $flags, $mode) or die "Can't open \"$database\" due to $!";

while ( ($key,$value) = each(%execs) ) {
    write;
}  

untie(%execs);

sub binary() {
  return O_BINARY if is_windows();
}

sub is_windows() {
    return $^O =~ /^(MS)?Win/;
}

   
    
    
  








Related examples in the same category

1.Creating and Assigning Data to a DBM File
2.Open DBM up for read write access
3.Opening an MLDBM database is similar to opening a regular DBM database:
4.Store hashes in a DBM file:
5.Using DBM databases with reports
6.Write out data into a DBM database
7.Copying from One DBM Format to Another