

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
The $[ Special Variable in Perl
Perl provides numerous special variables, which have their predefined meaning.
We have a special variable, which is written as $[. This special variable is a scalar containing the first index of all arrays. Because Perl arrays have zero-based indexing, $[ will almost always be 0. But if you set $[ to 1 then all your arrays will use on-based indexing. It is recommended not to use any other indexing other than zero. However, let's take one example to show the usage of $[ variable −
Example
#!/usr/bin/perl # define an array @foods = qw(pizza steak chicken burgers); print "Foods: @foods\n"; # Let's reset first index of all the arrays. $[ = 1; print "Food at \@foods[1]: $foods[1]\n"; print "Food at \@foods[2]: $foods[2]\n";
Output
This will produce the following result −
Foods: pizza steak chicken burgers Food at @foods[1]: pizza Food at @foods[2]: steak
- Related Questions & Answers
- Global Special Variable Types in Perl
- Perl Special Literals
- Filehandle Special Variables in Perl
- Perl Variable Context
- Regular Expression Special Variables in Perl
- __name__ (A Special variable) in Python
- The ? : Operator in Perl
- The Infinite Loop in Perl
- The carp Function in Perl
- The cluck Function in Perl
- The croak Function in Perl
- The confess Function in Perl
- The Match Operator in Perl
- The Substitution Operator in Perl
- The Translation Operator in Perl
Advertisements