- 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
Passing Hashes to Subroutines in Perl
When you supply a hash to a Perl subroutine or operator that accepts a list, then the hash is automatically translated into a list of key/value pairs. For example −
Example
#!/usr/bin/perl # Function definition sub PrintHash { my (%hash) = @_; foreach my $key ( keys %hash ) { my $value = $hash{$key}; print "$key : $value\n"; } } %hash = ('name' => 'Tom', 'age' => 19); # Function call with hash parameter PrintHash(%hash);
Output
When the above program is executed, it produces the following result −
name : Tom age : 19
- Related Articles
- Passing Lists to Subroutines in Perl
- Creating Hashes in Perl
- Add and Remove Elements in Perl Hashes
- Passing Arguments to a Subroutine in Perl
- What are Subroutines?
- Secure Hashes and Message Digest in Python
- Search an array of hashes in MongoDB?
- Secure hashes and message digests using Python (hashlib)
- References to Functions in Perl
- How to create Array in Perl?
- How to use Formats in Perl?
- Comments in Perl
- Whitespaces in Perl
- Dereferencing in Perl
- Passing to method geticon in SAPUI5

Advertisements