X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=pod%2Fperlfaq4.pod;h=08c76513fe6fcc0decf8456bc3b1c88b000271ad;hb=824215e2e3b067efbb0104afd616d77cb9526d1a;hp=f602d24b27527049750f198887d0477435ce0d01;hpb=213329dd3d3cdcddf6cc727a9d45053e2788898b;p=p5sagit%2Fp5-mst-13.2.git diff --git a/pod/perlfaq4.pod b/pod/perlfaq4.pod index f602d24..08c7651 100644 --- a/pod/perlfaq4.pod +++ b/pod/perlfaq4.pod @@ -1,6 +1,6 @@ =head1 NAME -perlfaq4 - Data Manipulation ($Revision: 1.8 $, $Date: 2001/11/09 08:06:04 $) +perlfaq4 - Data Manipulation ($Revision: 1.10 $, $Date: 2002/01/01 22:26:45 $) =head1 DESCRIPTION @@ -142,7 +142,7 @@ Using perl's built in conversion of 0x notation: $int = 0xDEADBEEF; $dec = sprintf("%d", $int); - + Using the hex function: $int = hex("DEADBEEF"); @@ -1635,13 +1635,13 @@ worry you, you can always reverse the hash into a hash of arrays instead: =head2 How can I know how many entries are in a hash? If you mean how many keys, then all you have to do is -take the scalar sense of the keys() function: +use the keys() function in a scalar context: - $num_keys = scalar keys %hash; + $num_keys = keys %hash; -The keys() function also resets the iterator, which in void context is -faster for tied hashes than would be iterating through the whole -hash, one key-value pair at a time. +The keys() function also resets the iterator, which means that you may +see strange results if you use this between uses of other hash operators +such as each(). =head2 How do I sort a hash (optionally by value instead of key)? @@ -1849,7 +1849,7 @@ in L. =head2 How can I use a reference as a hash key? -You can't do this directly, but you could use the standard Tie::Refhash +You can't do this directly, but you could use the standard Tie::RefHash module distributed with Perl. =head1 Data: Misc @@ -1919,10 +1919,10 @@ respectively. =head2 How do I keep persistent data across program calls? For some specific applications, you can use one of the DBM modules. -See L. More generically, you should consult the FreezeThaw, -Storable, or Class::Eroot modules from CPAN. Starting from Perl 5.8 -Storable is part of the standard distribution. Here's one example using -Storable's C and C functions: +See L. More generically, you should consult the FreezeThaw +or Storable modules from CPAN. Starting from Perl 5.8 Storable is part +of the standard distribution. Here's one example using Storable's C +and C functions: use Storable; store(\%hash, "filename");