Huub said:
Tad suggested that I'd put print statements in between to actually see
the values. I already did that, which is how I discovered this way
apparently doesn't work for numbers.
What "way" of doing *what* doesn't work for numbers?
How can I overwrite the value of the first position of @betaald, if I do
$betaald[0] = @betaald?
This question is non-sensical. That line of code *does* overwrite the
first position of @betaald. It puts the size of @betaald into the
first position of @betaald.
This overwrites the first position of $betaald.
This statement is also nonsensical. First, you have, until now, not
mentioned any such variable $betaald. We've been dealing with an array
@betaald. $betaald is a scalar variable. There is no such thing as
its "first position". Even assuming that was just a typo, isn't that
exactly what you just asked how to do?
If @betaald has the correct value, and the rest of my code doesn't work
for numbers,
More nonsense. @betaald does not have a "correct value". @betaald is
an array, and therefore has a list of values.
Again, what "doesn't work for numbers"?
how can I get that value into $betaald?
Get *what* value into $betaald?! Please read your post before you
post it. This is almost entirely gibberish.
I can't do "if (@betaald == @vergelijk) {}".
Of course you *can* do that... that compares the sizes of the two
arrays @betaald and @vergelijk. If the sizes are equal, the if block
is executed. If not, the if block is skipped. Is that what you want
to happen?
NO WHERE in this post have you said what you actually *want* to do, nor
*why* you want to do it.
I believe, however, that you have a major misconception about the way
scalar and array variables work in Perl. Allow me to attempt to
explain:
* @betaald is an array variable. It contains a list of values.
* $betaald is a scalar variable. It contains one single value.
* @betaald and $betaald have *NOTHING TO DO WITH EACH OTHER*. They are
completely un-related. Changing @betaald has no effect on $betaald,
nor vice versa.
* To access a certain element in @betaald, you append square-brackets
with the index number between them, and replace the @ with a $.
Therefore, $betaald[0] is the first element of @betaald. $betaald[1]
is the second element, etc.
* Again, $betaald[0] has NOTHING to do with $betaald. The first is an
element of the array @betaald, and the second is an unrelated scalar
variable.
* When you use a Perl array in scalar context (ex, comparing it to a
scalar, or assigning it to a scalar), it returns the size of that
array. For example, $foo = @betaald; assigns $foo to have the size of
@betaald. `if ($bar == @betaald) { } ` checks to see if $bar's value
is the same as the size of @betaald.
* Because elements of an array are themselves scalars, assigning to a
specific element of an array imposes scalar context. If I had an array
@stuff, and I said $stuff[0] = @betaald, that would assign the size of
@betaald to be the first element of @stuff. Likewise, saying
$betaald[0] = @betaald assigns the first element of @betaald to be the
size of @betaald (thus replacing whatever was already there)
I hope that helps to clarify Perl's arrays for you, so that you can
better express to us what it is you're actually *trying* to accomplish.
Paul Lalli