G
Gonzalo Castro
I'm have a string I am constructing with space delimited words. I would like
to iterate through each word later. I thought making an array from the
contents of the string would be the convenient way to approach this but I'm
not having any luck. Any ideas?
I construct a string in code similar to this:
$accumulator = ""
while (some condition)
{
$anotherString = getMeAnotherString();
$accumulator = $accumulator . " $anotherString"
}
Then I try to make an array but this is clearly not right. What's the right
way to do this?
@array = qw($accumulator);
When I iterate
for $element (@array)
{
print "element = $element";
}
I get this:
element = $accumulator
You might ask, "Why not simply add/push $anotherString onto an array first
instead of concatenating into a string?" And I would answer, "Well, because
I want the list of words to be the value part of a key/value hash and values
have to be scalar. Am I right?"
Thanks,
Gonzalo
to iterate through each word later. I thought making an array from the
contents of the string would be the convenient way to approach this but I'm
not having any luck. Any ideas?
I construct a string in code similar to this:
$accumulator = ""
while (some condition)
{
$anotherString = getMeAnotherString();
$accumulator = $accumulator . " $anotherString"
}
Then I try to make an array but this is clearly not right. What's the right
way to do this?
@array = qw($accumulator);
When I iterate
for $element (@array)
{
print "element = $element";
}
I get this:
element = $accumulator
You might ask, "Why not simply add/push $anotherString onto an array first
instead of concatenating into a string?" And I would answer, "Well, because
I want the list of words to be the value part of a key/value hash and values
have to be scalar. Am I right?"
Thanks,
Gonzalo