in reply to Do you really want to use an array there?

First of all, very interesting text. I never have looked the vec() function of Perl very well, but can be very important for a big amount of data.

Well, since vec is a CORE function, that work directly over the bits of the content of a string, it will much more faster, but don't forget that a vector is fixed, each element have the same size, is just an array of chars, and the Perl ARRAY is an array of SCALARS, that are much more complex.

Graciliano M. P.
"Creativity is the expression of the liberty".

  • Comment on Re: Do you really want to use an array there?

Replies are listed 'Best First'.
Re^2: Do you really want to use an array there?
by hv (Prior) on Jun 12, 2004 at 14:12 UTC

    There's nothing in principle forcing a vector to have elements all of the same size, you just have to be a bit careful with the indexing if they are not.

    What I do occasionally find frustrating is the lack of certain useful primitives when dealing with vectors, particularly vectors of booleans, since the resulting code can often become somewhat ugly and non-intuitive. Consider for example testing whether all(a_i & b_i) == 0:

    # in an integer unless ($a & $b) { ... } # in a vector unless (($a & $b) =~ /[^\0]/) { ... }

    I look forward to the promise of perl6 - where you could have a vector class, for example, "just like a string" except that it has a different concept of which strings are true. I think such a class would be difficult to achieve cleanly in perl5 without going down the path of tying/overloading, and losing most of the efficiency gains that caused you to turn to vectors in the first place.

    Hugo