- 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
Selecting Elements from Lists in Perl
The list notation in Perl is identical to that for arrays. You can extract an element from an array by appending square brackets to the list and giving one or more indices −
Example
#!/usr/bin/perl $var = (5,4,3,2,1)[4]; print "value of var = $var\n"
Output
This will produce the following result −
value of var = 1
Similarly, we can extract slices, although without the requirement for a leading @ character −
Example
#!/usr/bin/perl @list = (5,4,3,2,1)[1..3]; print "Value of list = @list\n";
Output
This will produce the following result −
Value of list = 4 3 2
- Related Articles
- Matching Boundaries & Selecting Alternatives in Perl
- Passing Lists to Subroutines in Perl
- Smallest Range Covering Elements from K Lists in C++
- Selecting Sibling Elements with CSS
- Selecting Child Elements with CSS
- Find smallest range containing elements from k lists in C++
- Get positive elements from given list of lists in Python
- Accessing Array Elements in Perl
- Slicing Array Elements in Perl
- Replacing Array Elements in Perl
- Accessing Hash Elements in Perl
- Program to interleave list elements from two linked lists in Python
- Adding and Removing Elements in Perl Array
- Add and Remove Elements in Perl Hashes
- Selecting Random Result from MySQL?

Advertisements