Re: Strings vs Arrays



M. Lewis wrote:

I now we can push (concatenate) data onto an array.

I would assume that we could concatenate data on to a string as well
with something like:

$newstring = $oldstring . $newdata

Yes.

Maybe this isn't correct though. I've not yet tried it.

My question is one method 'better' than the other? If so, why so?

Assuming there is no difference, then perhaps the determination of which
to use is dependent entirely on what is to be done with the data later
in the program.

It depends on the data and what you want to do with it. Strings and string
operations are usually more efficient than arrays and although most arrays can
be simulated using strings there are some list/array operations that are not
possible or harder to do on strings.

So what kind of data are you talking about? :-)



John
--
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order. -- Larry Wall
.



Relevant Pages

  • Re: I need some basic C++ help
    ... I think the idea of using arrays for strings (one that comes entirely ... the students need to see how strings can be constructed using arrays ... > One reason is that they spend much less time debugging. ...
    (comp.lang.cpp)
  • Re: more idle thinking: SiMPL
    ... int *pi; ... memory for strings and arrays are dynamicly allocated, ...
    (comp.lang.misc)
  • Re: Why does ANSI not define a function to determine the size of (m)allocated mem? (like _msize)
    ... Fortran 90 and up for arrays, and for character strings ... string length meaning variable at ALLOCATE time, ...
    (comp.lang.c)
  • Re: Option Compare Statement
    ... both arrays are always the same type. ... compare text,. ... Your first post regarding this in the vb.controls newsgroup was, ... strings, let's say A and B. Then I want to compare their values. ...
    (microsoft.public.vb.general.discussion)
  • Re: History of EQUAL on arrays?
    ... the special cases for strings and bit-vectors where EQUAL must look at ... preceded the availability of any general arrays. ... Indeed, in LISP 1.5, there was internally strings. ...
    (comp.lang.lisp)