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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.