programming-examples/perl/Database/Reads DBM file, printing entries with tie and untie function.pl
2019-11-15 12:59:38 +01:00

35 lines
581 B
Perl

#!/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/;
}