- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Perl Hash Variables
A hash is a set of key/value pairs. Hash variables are preceded by a percent (%) sign. To refer to a single element of a hash, you will use the hash variable name followed by the "key" associated with the value in curly brackets.
Here is a simple example of using hash variables −
Example
#!/usr/bin/perl %data = ('John Paul', 45, 'Lisa', 30, 'Kumar', 40); print "\$data{'John Paul'} = $data{'John Paul'}\n"; print "\$data{'Lisa'} = $data{'Lisa'}\n"; print "\$data{'Kumar'} = $data{'Kumar'}\n";
Output
This will produce the following result −
$data{'John Paul'} = 45 $data{'Lisa'} = 30 $data{'Kumar'} = 40
- Related Articles
- Accessing Hash Elements in Perl
- Getting Hash Size in Perl
- Perl Scalar Variables
- Perl Array Variables
- Creating Variables in Perl
- Perl CGI Environment Variables
- Filehandle Special Variables in Perl
- Extracting Keys and Values from Hash in Perl
- Checking for Key/Value Existence in Perl Hash
- State Variables via state() in Perl
- Regular Expression Special Variables in Perl
- Private Variables in a Subroutine in Perl
- How to check if a Perl hash already contains a key?
- Hash Functions and Hash Tables
- Distributed Hash Tables (DHTs)

Advertisements