- 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
References to Functions in Perl
While using Perl script, this might happen if you need to create a signal handler so you can produce a reference to a function by preceding that function name with \& and to dereference that reference you simply need to prefix reference variable using ampersand &. Following is an example −
Example
#!/usr/bin/perl # Function definition sub PrintHash { my (%hash) = @_; foreach $item (%hash) { print "Item : $item\n"; } } %hash = ('name' => 'Tom', 'age' => 19); # Create a reference to above function. $cref = \&PrintHash; # Function call using reference. &$cref(%hash);
Output
When the above program is executed, it produces the following result −
Item : name Item : Tom Item : age Item : 19
- Related Articles
- Create References in Perl
- Circular References in Perl
- Useful DBI Functions in Perl
- References in C++
- Examples of soft references and phantom references?
- How to use Interface References in C#?
- PHP References
- Pointers vs References in C++
- Types of References in Java
- Python Weak References
- PHP Spotting References
- PHP Unsetting References
- When to use references vs. pointers in C/C++
- How to use method references with Generics in Java?
- Reference to a constructor using method references in Java8

Advertisements