Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

All the indexes of array starts with 0.How to change the start index of array to "101";
How to see the documentation of perl modules installed in Unix box

Replies are listed 'Best First'.
Re: Array index
by ikegami (Patriarch) on Feb 16, 2010 at 07:18 UTC

    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.