Questions about this topic? Sign up to ask in the talk tab.
Perl/Basics/Hashes/Introduction
From NetSec
Revision as of 00:37, 19 July 2012 by Chantal21I (Talk | contribs) (Created page with "Hashes are prefixed by the '''%''' character. Hash element values are prefixed by '''$'''. A hash element may contain another hash, an array, or a scalar. * You can directly m...")
Hashes are prefixed by the % character. Hash element values are prefixed by $. A hash element may contain another hash, an array, or a scalar.
- You can directly modify the key inside of a hash
<syntaxhighlight lang="perl">$hash{'key'} = 'value';</syntaxhighlight> |
- You can also create a key => value pair on declaration
<syntaxhighlight lang="perl">my %hash = ('key' => 'value', 'key2' => 'value2');</syntaxhighlight> |
- Example:
<syntaxhighlight lang="perl">my %user; $user{'username'} = "hatter"; $user{'network'} = "irc.blackhatacademy.org"; print "The user " . $user{'username'} . " is connected to " . $user{'network'} . "\n"; </syntaxhighlight> |