Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

chaoticset (2105)

  (email not shown publicly)
AOL IM: chaoticset23 (Add Buddy, Send Message)
Yahoo! ID: illuminatus_foil (Add User, Send Message)

JAPH. (That's right -- I'm not Really Inexperienced any more.)

I'm not just here, I'm here [], and here [] too, I ramble randomly in my philosophical blog [] and my other blog []. Soon I'll come in a convenient six-pack.

Journal of chaoticset (2105)

Sunday October 07, 2001
08:40 AM

"Sort this, insert that. I'll make 'em all pay."

[ #906 ]
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. :-) )