in reply to Re: equivalent to Hash::Util for lists / arrays
in thread equivalent to Hash::Util for lists / arrays

...but I think neither of these two has the functionality the OP is specifically looking for, i.e. to lock an array against modification.

  • Comment on Re^2: equivalent to Hash::Util for lists / arrays

Replies are listed 'Best First'.
Re^3: equivalent to Hash::Util for lists / arrays
by LanX (Saint) on Dec 21, 2010 at 15:51 UTC
    The question was so poorly phrased that I was reluctant to reply, and IMHO toolic willently ignored it and chose the second best approach, the "anal tactic" of a "stubborn" reply... ;-)

    We can only speculate about the use case, but IIRC it's possible to define readonly lists with the constant pragma and use them with indices like arrays.

    UPDATE:

    use constant WEEKDAYS => qw( Sunday Monday Tuesday Wednesday Thursday Friday Saturday ); print "Today is ", (WEEKDAYS)[ (localtime)[WDAY] ], ".\n";

    and it's also possible to use read-only values for arrays.

    Cheers Rolf

      constant only makes the direct value a constant. Anything that might be referenced by those scalars are not made constant.