Clear questions and runnable code get the best and fastest answer |
|
PerlMonks |
Re: Newbie questionby Marshall (Canon) |
on Aug 23, 2022 at 10:53 UTC ( [id://11146306]=note: print w/replies, xml ) | Need Help?? |
Looks like homework, but you have done some work and asked for suggestions.
Update: 1) The name "isSumDigitsOdd" was chosen for a reason. The "is" prefix is one convention for indicating that this returns a flag/boolean value (yes/no). I expect 1 true, 0 false, but tolerate any one bits as true and only all zeroes as false. 2) The foreach loop was also done for a reason..I was able to work in the idea that this expects ints by using $int as the iterator value. All sorts of details wind up making a difference.
Also: I would write abs($_) or even abs $_ rather than just "abs" just to make things more clear even though the generated code is the same. Often there is some descriptive name other than just $_ and I use $_ for simple one line loops like above. Naming loop iterator variables is cheap and improves readability - do it often!
In Section
Seekers of Perl Wisdom
|
|