You are right, $code[$y]=$code[$y]++; shouldn't work, since it increments
after the assignment.
$code[$y]++; works for me, as does $code[$y]=++$code[$y];
This code:
@code = split //,"ABCD";
#values stored in @code are now A B C D
$y=0;
if($code[$y] ne "F"){
print "$code[$y]\n";
$code[$y]++;
print "$code[$y]\n";
$code[$y]=++$code[$y];
print "$code[$y]\n";
}
prints:
A
B
C
on my machine.
I apologize for being cryptic in my initial response and not looking deep
enough at your code.
/\/\ark
-----Original Message-----
From: Allison Ogle [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 18, 2002 11:05 AM
To: Mark Anderson
Subject: RE: Incrementing the letters in an array
If you're suggesting trying
$code[$y]=$code[$y]++;
it brings me one step closer in that it prints A A rather than A 1 but it
still doesn't increment. Unless you are suggesting something else.
$code[$y]++; doesn't work either.
-----Original Message-----
From: Mark Anderson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 18, 2002 1:59 PM
To: Allison Ogle
Subject: RE: Incrementing the letters in an array
I believe that the problem is your +1 should be ++.
/\/\ark
-----Original Message-----
From: Allison Ogle [mailto:[EMAIL PROTECTED]]
Sent: Thursday, April 18, 2002 10:58 AM
To: a a
Subject: Incrementing the letters in an array
Maybe it is because I am assigning my array to a line from another document
and not assigning letters dirtectly to the array because it still doesn't
work. It could be there is something wrong with my code too.
$word=<DATA>; #where <DATA> is the filehandle and therefore $word gets the
string from the inputfile. Something like ABCD for example
chomp $word;
@code = split //,$word; #this assigns thestring to the array @code. The
values stored in @code are now A B C D
$y=0;
if($code[$y] ne "F"){
print "$code[$y]\n";
$code[$y]=$code[$y]+1;
print "$code[$y]\n";}
This prints A and then 1. I can't figure out why. Is there something wrong
with my coding? Thanks for the help so far.
Allison
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]