in reply to Functions to Methods

You can program in COBOL(style wise) using java, but you probably shouldn't do so. Likewise making an array into an object seems more like an excercise of mimicing that other language rather than providing much real benefit.

Perl provides enough facilities for managing arrays that its not necessary to objectify them, other than to be a purist :-) At least I can't think of any methods that are lacking/missing. By facilities I mean -1 is the last element, scalar(@array) is the length/number of elements, $#array is the number of the last element. push/pop/unshift/shift - all for adding or removing from the front or the end. The common perl idiom is to use a HASH as your blessed object, and that hash may contain references to simpler types like an arrays. Not critcizing you for doing this..I've done fun things like this to see if I 'could' myself. I'm actually curious as to the reasons you want to objectify an array.

Replies are listed 'Best First'.
Re^2: Functions to Methods
by hv (Prior) on Jun 14, 2004 at 18:23 UTC
    Perl provides enough facilities for managing arrays that its not necessary to objectify them, other than to be a purist :-)

    To me, the main value of an Array class would be the potential to overload it: that would let me get something just like an array except for one small difference (or maybe except for a big difference).

    perl6 will in large part scratch that itch for me by having classes for all the builtin datatypes, though there will be some restrictions.

    At heart, though, I am a purist - I'd love to see a full "objects everywhere" a la Smalltalk, with a similarly well thought out set of fundamental classes (Bag, Set, Collection etc) - most of the time. The rest of the time I want the raw speed that handcoded builtins can offer. And sometimes both at the same time. And a pony.

    Hugo

      Have you tried tie'ing?

      ------
      We are the carpenters and bricklayers of the Information Age.

      Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

      I shouldn't have to say this, but any code, unless otherwise stated, is untested