sub insert_cards {
foreach $_ (@newcards) {
($newname, $newstock, $newshown) = split(/:/);
foreach $card (@cards) {
($name, $stock, $shown) = split(/:/, $card);
if ($newname eq $name) {
$stock = $newstock + $stock;
$card = "$name:$stock:$shown";
}
@cards = (@cards, $newcard);
}
}
}
Now, admittedly, this isn't a great improvement (hell, it doesn't *work*, and that would be manna from Heaven right now) but I thought it reads a little better.
The only problem with it is that using the $card variable allows me to see what was in the array, but I don't think it lets me *change* what was in the array. When I assign back:
$card = "$name:$stock:$shown"
I don't think it's going to work. I think it'll just assign that variable (scalar(@newcards) * scalar(@cards)) times, and that variable won't change the array.
"So push."
Can't. That leaves a duplicate.
It occurs to me that I could use the shift statment until it was at the end of the array and then change the number of elements in the array, but that seems inelegant.
Gotta be a better way to do this...
Could set up a counter. Count, count, count, and then
$cards[$i] = "$name:$stock:$shown";
but that really makes using the $card variable pointless, since I can only do half of what I need to with it. I'm sure there's a way to do it.
I guess for now I'll implement the counter solution, remove the $card variable, and stick to the rest of it the way it is. If I can figure out how to use $card for this, I'll try it again.
I'm nothing if not a code mess.
(Oh, and I never really thought anybody would actually *look* at my journal...imagine my surprise when someone actually said something to me in his! If you see this, chromatic, I'll check out Perl Monks, but I won't post there until the program's hurt me a little more. Thank you for the advice. :-) )