SEARCH RESULTS

FAQ

"How do I merge two hashes?" in perlfaq4

If you want to preserve the original hashes, copy one hash (%hash1) to a new hash (%new_hash), then add ... the keys from the other hash (%hash2 to the new hash.

"What's the difference between "delete" and "undef" with hashes?" in perlfaq4

If a key $key is present in %hash, exists($hash{$key}) will return true. ... The value for a given key can be undef, in which case $hash{$key} will be undef while exists $hash{$key

"How do I process an entire hash?" in perlfaq4

Data: Hashes (Associative Arrays) How do I process an entire hash? ... ) { my $value = $hash{$key} ... } If the hash is very large, you might not want

"How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays?" in perlfaq4

How can I make the Perl equivalent of a C structure/C++ class/hash or array of hashes or arrays? ... Usually a hash ref, perhaps like this: $record = { NAME => "Jason", EMPNO =>

"How can I use a reference as a hash key?" in perlfaq4

How can I use a reference as a hash key? ... ::RefHash module, which does the required work for you.

"How can I check if a key exists in a multilevel hash?" in perlfaq4

If you want to check three keys deep, you might naïvely try this: my %hash; if( exists $hash ... $hash = $hash->{$key}; } return 1; }

"How can I prevent addition of unwanted keys into a hash?" in perlfaq4

How can I prevent addition of unwanted keys into a hash? ... Methods for creating and dealing with restricted hashes are exported by the Hash::Util module.

"How can I know how many entries are in a hash?" in perlfaq4

How can I know how many entries are in a hash? ... : my $key_count = keys %hash; # must be scalar context!

"How can I always keep my hash sorted?" in perlfaq4

How can I always keep my hash sorted? ... The Tie::IxHash module from CPAN might also be instructive.

"How do I look up a hash element by value?" in perlfaq4

How do I look up a hash element by value? ... If it does worry you, you can always reverse the hash into a hash of arrays instead: while (my (

"How do I sort a hash (optionally by value instead of key)?" in perlfaq4

my @keys = sort { $hash{$a} <=> $hash{$b} } keys %hash; From there we can get more complex. ... %hash;

"Why does passing a subroutine an undefined element in a hash create it?" in perlfaq4

my %hash = (); my $value = $hash{ 'foo' }; print "This won't print\n" if exists $hash{ 'foo' ... $hash{ 'foo' }; sub my_sub { # $_[0] = 'bar'; # create hash key in case you do this

"Why does defined() return true on empty arrays and hashes?" in perlfaq4

Why does defined() return true on empty arrays and hashes? ... is that you should probably only use defined on scalars or functions, not on aggregates (arrays and hashes

"Why don't my tied hashes make the defined/exists distinction?" in perlfaq4

Why don't my tied hashes make the defined/exists distinction? ... This depends on the tied hash's implementation of EXISTS().

"How do I test whether two arrays or hashes are equal?" in perlfaq4

How do I test whether two arrays or hashes are equal? ... "the same" : "different"; This approach also works for comparing hashes.

"How can I get the unique keys from two hashes?" in perlfaq4

How can I get the unique keys from two hashes? ... First you extract the keys from the hashes into lists, then solve the "removing duplicates" problem described

"How can I make my hash remember the order I put elements into it?" in perlfaq4

Use the Tie::IxHash from CPAN. ... use Tie::IxHash; tie my %myhash, 'Tie::IxHash'; for (my $i=0; $i<20; $i++) { $myhash

"What happens if I add or remove keys from a hash while iterating over it?" in perlfaq4

What happens if I add or remove keys from a hash while iterating over it? ... If you iterate through the hash with each(), you can delete the key most recently returned without worrying

"How can I free an array or hash so my program shrinks?" in perlfaq3

How can I free an array or hash so my program shrinks?

"How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?" in perlfaq7

How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}? ... func( \$some_scalar ); func( \@some_array ); func( [ 1 .. 10 ] ); func( \%some_hash

More results found. Refine your search terms or show all FAQ results.

Functions

keys - retrieve list of indices from a hash

$hash{$a} } keys %hash) { printf "%4d %s\n", $hash{$key}, $key; } Used as an lvalue, keys ... allows you to increase the number of hash buckets allocated for the given hash.

values - return a list of the values in a hash

hash. ... for (values %hash) { s/foo/bar/g } # modifies %hash values for (@hash{keys %hash}) {

each - retrieve the next key/value pair from a hash

each HASH each ARRAY When called on a hash in list context, returns a 2-element list consisting ... The actual random order is specific to a given hash; the exact same series of operations on two hashes

delete - deletes a value from a hash

11 $scalar = delete @hash{qw(foo bar)}; # $scalar is 22 my @array = delete @hash{qw(foo baz ... : foreach my $key (keys %HASH) { delete $HASH{$key}; } foreach my $index (0 ..

map - apply a change to a list to get back a new list with the changes

my %hash = map { get_a_key_for($_) => $_ } @array; is just a funny way to write my %hash; foreach ... perl guesses BLOCK. right my %hash = map {; "\L$_" => 1 } @array # this also works my %hash = map

exists - test whether a hash key is present

exists EXPR Given an expression that specifies an element of a hash, returns true if the specified ... print "Exists\n" if exists $hash{$key}; print "Defined\n" if defined $hash{$key}; print

reverse - flip a string or a list

hash. ... Also, this has to unwind one hash and build a whole new one, which may take some time on a large hash

dbmclose - breaks binding on a tied dbm file

dbmclose HASH [This function has been largely superseded by the untie function.] ... Breaks the binding between a DBM file and a hash. Portability issues: "dbmclose" in perlport.

dbmopen - create binding on a tied dbm file

This binds a dbm(3), ndbm(3), sdbm(3), gdbm(3), or Berkeley DB file to a hash. ... HASH is the name of the hash.

undef - remove a variable or function definition

Use only on a scalar value, an array (using @), a hash (using %), a subroutine (using &), or a typeglob ... Saying undef $hash{$key} will probably not do what you expect on most predefined variables or DBM list

defined - test whether a value, variable, or function is defined

) { print "has hash members\n" } When used on a hash element, it tells you whether the value is ... defined, not whether the key exists in the hash.

length - return the number of characters in a string

This function cannot be used on an entire array or hash to find out how many elements these have. ... For that, use scalar @array and scalar keys %hash, respectively.

chop - remove the last character from a string

If VARIABLE is a hash, it chops the hash's values, but not its keys, resetting the each iterator in the

local - create a temporary value for a global variable (dynamic scoping)

See "Temporary Values via local()" in perlsub for details, including issues with tied arrays and hashes ... The delete local EXPR construct can also be used to localize the deletion of array/hash elements to the

crypt - one-way passwd-style encryption

crypt is a one-way hash function. ... This ensures crypt will hash the new string with the same salt as the digest.

reset - clear all variables of a given name

All variables (scalars, arrays, and hashes) in the current package beginning with one of those letters ... Resetting "A-Z" is not recommended because you'll wipe out your @ARGV and @INC arrays and your %ENV hash

chomp - remove a trailing record separator from a string

chomp; # avoid \n on last field my @array = split(/:/); # ... } If VARIABLE is a hash ... , it chomps the hash's values, but not its keys, resetting the each iterator in the process.

lock - get a thread lock on a variable, subroutine, or method

value returned is the scalar itself, if the argument is a scalar, or a reference, if the argument is a hash

opendir - open a directory

If DIRHANDLE is an undefined scalar variable (or array or hash element), the variable is assigned a reference

tie - bind a variable to an object class

) = each %HIST) { print $key, ' = ', unpack('L', $val), "\n"; } A class implementing a hash ... See perltie, Tie::Hash, Tie::Array, Tie::Scalar, and Tie::Handle.

More results found. Refine your search terms or show all function results.

Documentation

Hash::Util - A selection of general-utility hash subroutines

lock_hash unlock_hash lock_hash(%hash); lock_hash() locks an entire hash, making all keys and values ... lock_hash_recurse unlock_hash_recurse lock_hash_recurse(%hash); lock_hash() locks an entire hash

Tie::Hash - base class definitions for tied hashes

NAME Tie::Hash, Tie::StdHash, Tie::ExtraHash - base class definitions for tied hashes SYNOPSIS package ... , 'NewHash'; tie %new_std_hash, 'NewStdHash'; tie %new_extra_hash, 'NewExtraHash', sub {warn "Doing

Tie::RefHash - Use references as hash keys

in hashes-of-hashes, use Tie::RefHash::Nestable, included as part of Tie::RefHash. ... hash.

Tie::SubstrHash - Fixed-table-size, fixed-key-length hashing

NAME Tie::SubstrHash - Fixed-table-size, fixed-key-length hashing SYNOPSIS require Tie::SubstrHash ... ; tie %myhash, 'Tie::SubstrHash', $key_len, $value_len, $table_size; DESCRIPTION The Tie::SubstrHash

Test2::Util::HashBase - Build hash based classes.

NAME Test2::Util::HashBase - Build hash based classes. ... @list = Test2::Util::HashBase::attr_list($class) @list = $class->Test2::Util::HashBase::attr_list(

Hash::Util::FieldHash - Support for Inside-Out Classes

NAME Hash::Util::FieldHash - Support for Inside-Out Classes SYNOPSIS ### Create fieldhashes use Hash ... \ %hash, 0; # make %hash a field hash my $result = _fieldhash \ %hash, 1; _fieldhash is the internal

Tie::Hash::NamedCapture - Named regexp capture buffers

NAME Tie::Hash::NamedCapture - Named regexp capture buffers SYNOPSIS tie my %hash, "Tie::Hash::NamedCapture ... "; # %hash now behaves like %+ tie my %hash, "Tie::Hash::NamedCapture", all => 1; # %hash now access

Tie::Memoize - add data to hash when needed

NAME Tie::Memoize - add data to hash when needed SYNOPSIS require Tie::Memoize; tie %hash, 'Tie::Memoize ... AUTHOR Ilya Zakharevich mailto:perl-module-hash-memoize@ilyaz.org.

Config::Extensions - hash lookup of which core extensions were built.

NAME Config::Extensions - hash lookup of which core extensions were built. ... }) { # This perl has PerlIO::via built } DESCRIPTION The Config::Extensions module provides a hash

B::Op_private - OP op_private flag definitions

any) for that bit: $B::Op_private::bits{aelem}{7} eq 'OPpLVAL_INTRO'; For bit fields, it returns a hash ... Op_private::bits{aelem}{5}; $bitfield = $B::Op_private::bits{aelem}{6}; The general format of this hash

Config::Perl::V - Structured data retrieval of perl -V output

$conf = plv2hash ($text [, ...]) ... The hash structure The returned hash consists of 4 parts: build This information is extracted from

TAP::Parser::YAMLish::Writer - Write YAMLish data

write( $data, sub { my $line = shift; print "$line\n"; } ); DESCRIPTION Encodes a scalar, hash ... Instance Methods write $writer->write($obj, $output ); Encode a scalar, hash reference or array reference

perlref - Perl references and nested data structures

, hashes of arrays, arrays of hashes of functions, and so on. ... Pseudo-hashes: Using an array as a hash Pseudo-hashes have been removed from Perl.

NDBM_File - Tied access to ndbm files

; aborting"; # Now read and change the hash $h{newkey} = newvalue; print $h{oldkey}; ... ... The name of the file you want to tie to the hash. Flags.

ODBM_File - Tied access to odbm files

(Ths tells Perl to use the ODBM_File package to perform the functions of the hash.) ... The name of the file you want to tie to the hash. Flags.

SDBM_File - Tied access to sdbm files

; aborting"; # Now read and change the hash $h{newkey} = newvalue; print $h{oldkey}; ... ... tie %hash, 'SDBM_File', $basename, $modeflags, $perms; tie %hash, 'SDBM_File', $dirfile, $modeflags

Encode::Encoding - Encode Implementation Base Class

The mapping of encoding name to object is via the %Encode::Encoding hash. ... Though you can directly manipulate this hash, it is strongly encouraged to use this base class module

VMS::DCLsym - Perl extension to manipulate DCL symbols

Tied hash interface This interface lets you treat the DCL symbol table as a Perl associative array, ... In some cases, this allows you finer control than using a tied hash aggregate.

perldata - Perl data types

For example, you stick 10,000 things in a hash, but evaluating %HASH in scalar context reveals "1/16" ... Key/Value Hash Slices Starting in Perl 5.20, a hash slice operation with the % symbol is a variant of

Storable - persistence for Perl data structures

restricted hashes Perl 5.8 adds support for restricted hashes, which have keys restricted to a given ... The cperl PERL_PERTURB_KEYS_TOP hash strategy has a known problem with restricted hashes.

More results found. Refine your search terms or show all documentation results.

Perldeltas

"Array and hash" in perl5160delta

Deleting the current hash iterator (the hash element that would be returned by the next call to each ... When hash elements are deleted in void context, the internal hash entry is now freed before the value

"Hash randomization" in perl5180delta

Hash randomization The seed used by Perl's hash function is now random. ... what the current hash seed is.

"Hash Randomisation" in perl581delta

Incompatible Changes Hash Randomisation Mainly due to security reasons, the "random ordering" of hashes ... If some particular order is really important, use tied hashes: for example the Tie::IxHash module which

"Hash overhaul" in perl5180delta

Hash overhaul Changes to the implementation of hashes in perl v5.18.0 will be one of the most visible ... By default, two distinct hash variables with identical keys and values may now provide their contents

"Restricted Hashes" in perl58delta

Restricted Hashes A restricted hash is restricted to a certain set of keys, no keys outside the set ... No new syntax is involved: the Hash::Util module is the interface.

"Hash Randomisation" in perl582delta

Core Enhancements Hash Randomisation The hash randomisation introduced with 5.8.1 has been amended.

"Hash::Util::hash_seed() now returns a string" in perl5180delta

Hash::Util::hash_seed() now returns a string Hash::Util::hash_seed() now returns a string instead of ... (SipHash uses a 16 byte seed.)

"New hash functions" in perl5180delta

New hash functions Perl v5.18 includes support for multiple hash functions, and changed the default

"Pseudo-hashes are supported" in perl5005delta

Pseudo-hashes are supported See perlref.

"Default Hash Function Change" in perl5280delta

StadtX hash. ... -DPERL_HASH_FUNC_SIPHASH13 -DPERL_HASH_FUNC_STADTX -DPERL_HASH_FUNC_ZAPHOD32 To disable

"Pseudo-hashes work better" in perl561delta

Pseudo-hashes work better Dereferencing some types of reference values in a pseudo-hash, such as $ph ... See "Pseudo-hashes: Using an array as a hash" in perlref.

"Pseudo-hashes work better" in perl56delta

Pseudo-hashes work better Dereferencing some types of reference values in a pseudo-hash, such as $ph ... See "Pseudo-hashes: Using an array as a hash" in perlref.

"Tied hashes in scalar context" in perl581delta

Tied hashes in scalar context Tied hashes do not currently return anything useful in scalar context, ... of a hash in scalar context.

"See also: hash overhaul" in perl5180delta

Security See also: hash overhaul Some of the changes in the hash overhaul were made to enhance security ... Incompatible Changes See also: hash overhaul Some of the changes in the hash overhaul are not fully

"Anonymous hash and array constructors" in perl5100delta

Anonymous hash and array constructors The anonymous hash and array constructors now take 1 op in the ... optree instead of 3, now that pp_anonhash and pp_anonlist return a reference to a hash/array when the

"Hints hash API" in perl5140delta

Hints hash API A new C API for introspecting the hinthash %^H at runtime has been added.

"Lexical array and hash assignments" in perl5140delta

Lexical array and hash assignments An earlier optimisation to speed up my @array = ... and my %hash

"scalar(%hash) return signature changed" in perl5260delta

scalar(%hash) return signature changed The value returned for scalar(%hash) will no longer show information ... about the buckets allocated in the hash.

"New "Pseudo-hashes are deprecated"" in perl581delta

New "Pseudo-hashes are deprecated" This warning should have been already in 5.8.0, since they are.

"(Reminder) Pseudo-hashes are deprecated (really)" in perl581delta

(Reminder) Pseudo-hashes are deprecated (really) Pseudo-hashes were deprecated in Perl 5.8.0 and will ... Each attempt to access pseudo-hashes will trigger the warning Pseudo-hashes are deprecated.

More results found. Refine your search terms or show all perldelta results.