Re: Strings vs Arrays



cajun@xxxxxxxxxxxx (M. Lewis) writes:

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

It's *probably* thought of more often as *adding* an item/element onto an
array (rather than as concatenate). In array we are not merging nor are we
making the all as merged/fused into just one unit. Instead we are increasing
the number of elements in the array. Each element of the array remains as it
was, nothing gets merged/fused together as one.

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

$newstring = $oldstring . $newdata

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.

As DJ offered a hint. As in use whichever tool you need so as to accomplish
whichever specific task is at hand.

An array may contain multiple strings/elements. Array can be iterated over.

String is just one string; there's nothing to loop or iterate over.

And, *why* haven't you tried it yet? The term for it is hands on or
kinisthetic learning.

The next is tested, works.

#!/usr/bin/perl
use warnings;
use strict;

my $oldstring = 'string_item_1';
my $newdata = 'string_item_2';
print $oldstring, " \<\< \$oldstring\n";
print $newdata, " \<\< \$newdata\n";

# my $newstring = '$oldstring . $newdata';
# my $newstring = "$oldstring . $newdata . string_item_3";
my $newstring = "$oldstring" . " $newdata" . " string_item_3";
print "$newstring", " \<\< \$newstring\n";

# foreach ( $newstring ) {}# oop won't work
my @array = qw(Joe Larry Moe);
foreach (@array ) { # works
print $_, " \<\< comical person\n";
}
print "The listed comics may not be mathematicians nor rocket scientists\n";
# end

--
Alan.
.



Relevant Pages

  • Help in French|Spanish|German translation.
    ... I am also an author of User-defined string functions. ... WORDTRANEX (cSearched, cArExpressionSought | cExpressionSough, ... each string of the array is searched ... If the parameter nArStartOccurrence is -1 or omitted, the replacement starts ...
    (microsoft.public.fox.helpwanted)
  • Re: passing a string to a dll
    ... Joe, I really appreciate you taking the time to demonstrate this. ... sure how I would implement indexing it for random alphanumeric codes. ... I might handle the array. ... I actually have been wondering if I could use a second string ...
    (microsoft.public.vc.mfc)
  • Re: passing a string to a dll
    ... I might handle the array. ... I actually have been wondering if I could use a second string ... look at insertion cost, organization cost, and search cost. ...
    (microsoft.public.vc.mfc)
  • RE: Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Structure conversion from C++ to VB-2008?
    ... One of the most important structures is AmiVar structure. ... point number, the array of floating point numbers, a string or IDispatch ... Dim 13012679 as Integer ...
    (microsoft.public.dotnet.languages.vb)