All the indexes of array starts with 0.How to change the start index of array to "101";
Subtract 101 from the index.
use constant BASE => 101;
$a[$i - BASE] = 'a';
This will still work:
print("The array has ", 0+@a, " elements\n");
for (@a) {
...
}
without preventing you from doing
for my $i (101..200) {
... $a[$i - BASE] ...
}
There's also $[, but
- It affects all arrays
- It affects substr
- It's used is discouraged.
- It will issue a deprecation warning by default in Perl 5.12.
- It will be removed in Perl 5.14.
I'd avoid it.
How to see the documentation of perl modules installed in Unix box
perldoc or online on CPAN
Update: Compensated for a warning. There needs to be space between - and BASE.
|