- 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 Lists to Subroutines in Perl
Because the @_ variable is an array in Perl, it can be used to supply lists to a subroutine. However, because of the way in which Perl accepts and parses lists and arrays, it can be difficult to extract the individual elements from @_. If you have to pass a list along with other scalar arguments, then make list as the last argument as shown below −
Example
#!/usr/bin/perl # Function definition sub PrintList { my @list = @_; print "Given list is @list\n"; } $a = 10; @b = (1, 2, 3, 4); # Function call with list parameter PrintList($a, @b);
Output
When the above program is executed, it produces the following result −
Given list is 10 1 2 3 4
- Related Articles
- Passing Hashes to Subroutines in Perl
- Passing Arguments to a Subroutine in Perl
- Selecting Elements from Lists in Perl
- What are Subroutines?
- 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
- Passing array to method in Java
- Passing arrays to methods in C#?
- Passing Arrays to Function in C++
- Why to Learn Perl?

Advertisements