Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
The ONE Campaign to make poverty history

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Surveys

Features
HOWTOs
News Archive
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 212 guest(s) and 0 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  

perldbmfilter



SYNOPSIS

           $db = tie %hash, 'DBM', ...

           $old_filter = $db->filter_store_key  ( sub { ... } ) ;
           $old_filter = $db->filter_store_value( sub { ... } ) ;
           $old_filter = $db->filter_fetch_key  ( sub { ... } ) ;
           $old_filter = $db->filter_fetch_value( sub { ... } ) ;


DESCRIPTION

       The four "filter_*" methods shown above are available in
       all the DBM modules that ship with Perl, namely DB_File,
       GDBM_File, NDBM_File, ODBM_File and SDBM_File.

       Each of the methods work identically, and are used to
       install (or uninstall) a single DBM Filter. The only dif­
       ference between them is the place that the filter is
       installed.

       To summarise:

       filter_store_key
            If a filter has been installed with this method, it
            will be invoked every time you write a key to a DBM
            database.

       filter_store_value
            If a filter has been installed with this method, it
            will be invoked every time you write a value to a DBM
            database.

       filter_fetch_key
            If a filter has been installed with this method, it
            will be invoked every time you read a key from a DBM
            database.

       filter_fetch_value
            If a filter has been installed with this method, it
            will be invoked every time you read a value from a
            DBM database.

       You can use any combination of the methods from none to
       all four.

       All filter methods return the existing filter, if present,
       or "undef" in not.

       To delete a filter pass "undef" to it.

       The Filter

       When each filter is called by Perl, a local copy of $_
       will contain the key or value to be filtered. Filtering is
       Perl application will have to manage NULL termination
       itself. When you write to the database you will have to
       use something like this:

           $hash{"$key\0"} = "$value\0" ;

       Similarly the NULL needs to be taken into account when you
       are considering the length of existing keys/values.

       It would be much better if you could ignore the NULL ter­
       minations issue in the main application code and have a
       mechanism that automatically added the terminating NULL to
       all keys and values whenever you write to the database and
       have them removed when you read from the database. As I'm
       sure you have already guessed, this is a problem that DBM
       Filters can fix very easily.

           use strict ;
           use warnings ;
           use SDBM_File ;
           use Fcntl ;

           my %hash ;
           my $filename = "/tmp/filt" ;
           unlink $filename ;

           my $db = tie(%hash, 'SDBM_File', $filename, O_RDWR|O_CREAT, 0640)
             or die "Cannot open $filename: $!\n" ;

           # Install DBM Filters
           $db->filter_fetch_key  ( sub { s/\0$//    } ) ;
           $db->filter_store_key  ( sub { $_ .= "\0" } ) ;
           $db->filter_fetch_value(
               sub { no warnings 'uninitialized' ;s/\0$// } ) ;
           $db->filter_store_value( sub { $_ .= "\0" } ) ;

           $hash{"abc"} = "def" ;
           my $a = $hash{"ABC"} ;
           # ...
           undef $db ;
           untie %hash ;

       The code above uses SDBM_File, but it will work with any
       of the DBM modules.

       Hopefully the contents of each of the filters should be
       self-explanatory. Both "fetch" filters remove the termi­
       nating NULL, and both "store" filters add a terminating
       NULL.

       Another Example -- Key is a C int.

           use warnings ;
           use DB_File ;
           my %hash ;
           my $filename = "/tmp/filt" ;
           unlink $filename ;

           my $db = tie %hash, 'DB_File', $filename, O_CREAT|O_RDWR, 0666, $DB_HASH
             or die "Cannot open $filename: $!\n" ;

           $db->filter_fetch_key  ( sub { $_ = unpack("i", $_) } ) ;
           $db->filter_store_key  ( sub { $_ = pack ("i", $_) } ) ;
           $hash{123} = "def" ;
           # ...
           undef $db ;
           untie %hash ;

       The code above uses DB_File, but again it will work with
       any of the DBM modules.

       This time only two filters have been used -- we only need
       to manipulate the contents of the key, so it wasn't neces­
       sary to install any value filters.


SEE ALSO

       DB_File, GDBM_File, NDBM_File, ODBM_File and SDBM_File.


AUTHOR

       Paul Marquess

perl v5.8.1                 2003-09-02           PERLDBMFILTER(1)

An undefined database error occurred. SELECT distinct pages.pagepath,pages.pageid FROM pages, page2command WHERE pages.pageid = page2command.pageid AND commandid =


  

More information about the site can be found in the FAQ


Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List

Did You Know?
The Linux Tutorial welcomes your suggestions and ideas.


Friends



Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content (C) 1994-2013 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download software ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.09 Seconds