in reply to Re: Re: help with algorithm
in thread help with algorithm
That code is working fine. You just make an error in the way you check the returned values.
@newtest = days($test); foreach $num (@newtest) { print "$newtest[$num]\n"; }
The array, @newtest, is assigned ('Tuesday', 'Wednesday') as expected but you iterate over it and use each element as an index back into @newtest. You are printing $newtest['Tuesday'] and $newtest['Wednesday'] but both 'Tuesday' and 'Wednesday' evaluate to 0 in numerical context. So, You print $newtest[0] twice and $newtest[0] holds 'Tuesday'. That's why you print 'Tuesday' twice.
Try writing that loop as:
foreach $day (@newtest) { print $day,"\n"; }
-sauoq "My two cents aren't worth a dime.";
|
|---|