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

  • 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: Array Type Mismatch
    ... Dim resultAs String ... I am still somewhat confused as to why nothing is stored in the array. ... Public Function TextBoxGetLine(....arguments... ...
    (microsoft.public.access.formscoding)
  • Re: NumberFormatException:please help me......!!!
    ... Record that has string and array of double as members) and file could ... follows it on a line of the input file, you could use the String as a key to ... contain String representations of doubles. ...
    (comp.lang.java.programmer)
  • Help in Spanish translation of the description of UDFs
    ... functions of minimum / maximum values among elements of an array column. ... GETALLWORDS- Inserts the words from a string into a global dimensioned ... WORDTRAN- Searches a character string for occurrences of a first word, ... ARRAYSUM- Returns the sum of all or a specified range of numeric (and/or ...
    (microsoft.public.fox.helpwanted)