FreeKB - Hash (create empty hash)
Perl - Hash (create empty hash)

Here are different ways to create an empty hash named "hash".

my %hash;
my %hash = ();

 

Keys that contain no values (empty keys) can be created like this.

%hash = (
  name_key => "", 
  id_key => "", 
  department_key => ""
);

 

Or, like this.

$hash{name_key}       = undef;
$hash{id_key}         = undef;
$hash{department_key} = undef;

 

Or, like this.

$hash{name_key}       = "";
$hash{id_key}         = "";
$hash{department_key} = "";

 

Dumper can be used to display the structure of the hash.

use Data::Dumper;
print Dumper \%hash;

 

Which will display the data structure of the hash.

$VAR1 = {
           'name_key' => '',
           'id_key' => '',
           'department_key' => ''
        };

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter 072fa in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |