On Jun 14, David Gilden said:

>sub choseColor{
>return int (rand ($#colors + 1));
>}
>
># $#colors + 1 --> better written as  int (rand @colors);
># is this ok, using an @array as in a loop to 
># like:  while ($i < @array) {... do something...; $i++} 

Yes, it's fine.  An array in SCALAR CONTEXT returns its length -- the
number of elements it contains.

># never happens ?!?
>
> print "###dup###\n" if ($color_dup == $color_choice);

It never happens because "#hello" and "#goodbye" have the same NUMERIC
value, 0.  You want to use string comparison here:

  print "dup\n" if $color_dup eq $color_choice;

If you were using warnings (via the -w switch, or the 'use warnings'
pragma in Perl 5.6) you'd be told you were using a string in numerical
context.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to