This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't use /dev/tty if it happens to exist on Windows
[perl5.git] / pod / perldbmfilter.pod
index f10bdd0..0413bf9 100644 (file)
@@ -4,9 +4,8 @@ perldbmfilter - Perl DBM Filters
 
 =head1 SYNOPSIS
 
-    my $db = tie my %hash, 'DBM', ...;
+    $db = tie %hash, 'DBM', ...
 
-    my $old_filter;
     $old_filter = $db->filter_store_key  ( sub { ... } );
     $old_filter = $db->filter_store_value( sub { ... } );
     $old_filter = $db->filter_fetch_key  ( sub { ... } );
@@ -18,7 +17,7 @@ The four C<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
+Each of the methods works identically, and is used to install (or
 uninstall) a single DBM Filter. The only difference between them is the
 place that the filter is installed.
 
@@ -36,7 +35,6 @@ every time you write a key to a DBM database.
 If a filter has been installed with this method, it will be invoked
 every time you write a value to a DBM database.
 
-
 =item B<filter_fetch_key>
 
 If a filter has been installed with this method, it will be invoked
@@ -52,7 +50,7 @@ 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 C<undef>
-in not.
+if not.
 
 To delete a filter pass C<undef> to it.
 
@@ -62,7 +60,7 @@ When each filter is called by Perl, a local copy of C<$_> will contain
 the key or value to be filtered. Filtering is achieved by modifying
 the contents of C<$_>. The return code from the filter is ignored.
 
-=head2 An Example -- the NULL termination problem.
+=head2 An Example: the NULL termination problem.
 
 DBM Filters are useful for a class of problems where you I<always>
 want to make the same transformation to all keys, all values or both.
@@ -74,7 +72,7 @@ when Perl writes to DBM databases it doesn't use NULL termination, so
 your 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" ;
+    $hash{"$key\0"} = "$value\0";
 
 Similarly the NULL needs to be taken into account when you are considering
 the length of existing keys/values.
@@ -92,7 +90,7 @@ fix very easily.
     use Fcntl;
 
     my %hash;
-    my $filename = '/tmp/filt';
+    my $filename = "filt";
     unlink $filename;
 
     my $db = tie(%hash, 'SDBM_File', $filename, O_RDWR|O_CREAT, 0640)
@@ -105,8 +103,8 @@ fix very easily.
         sub { no warnings 'uninitialized'; s/\0$// } );
     $db->filter_store_value( sub { $_ .= "\0" } );
 
-    $hash{abc} = 'def';
-    my $a = $hash{ABC};
+    $hash{"abc"} = "def";
+    my $a = $hash{"ABC"};
     # ...
     undef $db;
     untie %hash;
@@ -119,13 +117,13 @@ self-explanatory. Both "fetch" filters remove the terminating NULL,
 and both "store" filters add a terminating NULL.
 
 
-=head2 Another Example -- Key is a C int.
+=head2 Another Example: Key is a C int.
 
 Here is another real-life example. By default, whenever Perl writes to
 a DBM database it always writes the key and value as strings. So when
 you use this:
 
-    $hash{12345} = 'something';
+    $hash{12345} = "something";
 
 the key 12345 will get stored in the DBM database as the 5 byte string
 "12345". If you actually want the key to be stored in the DBM database
@@ -138,16 +136,16 @@ Here is a DBM Filter that does it:
     use warnings;
     use DB_File;
     my %hash;
-    my $filename = '/tmp/filt';
+    my $filename = "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';
+    $db->filter_fetch_key  ( sub { $_ = unpack("i", $_) } );
+    $db->filter_store_key  ( sub { $_ = pack ("i", $_) } );
+    $hash{123} = "def";
     # ...
     undef $db;
     untie %hash;
@@ -155,7 +153,7 @@ Here is a DBM Filter that does it:
 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
+This time only two filters have been used; we only need to manipulate
 the contents of the key, so it wasn't necessary to install any value
 filters.