mabeuf has asked for the wisdom of the Perl Monks concerning the following question:
Hey monks. Ive been getting back on the perl bandwagon after about 2 years. My last (very small) attempts were based solely on editing and modifying someone elses code during uni but this time Ive been working through the Llama book and doing it properly. I want to spend more time doing and less time reading so Ive been getting my family to set me problems to fix as I go along (chapter 4 now!).
Seen as there are no right answers if you guys and gals see any errors in style or superfluous-ness (its a word!) I'd appreciate any feedback.
This was to work out all the factors of a number:Thanks for looking M#!/usr/bin/perl use warnings; print "Type number you want factorised: \n"; chomp($no = <STDIN>); @int = (1..($no/2)); print "The factors of $no are: \n"; foreach $int (@int) { $div = $no/$int; $remainder = $no % $int; if ($remainder == 0){ print "$div\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: First code - Factors
by GrandFather (Saint) on Sep 22, 2010 at 11:02 UTC | |
|
Re: First code - Factors
by Khen1950fx (Canon) on Sep 22, 2010 at 11:58 UTC | |
|
Re: First code - Factors
by roboticus (Chancellor) on Sep 22, 2010 at 13:59 UTC | |
|
Re: First code - Factors
by Anonymous Monk on Sep 22, 2010 at 10:58 UTC | |
by JavaFan (Canon) on Sep 22, 2010 at 11:40 UTC | |
by Anonymous Monk on Sep 22, 2010 at 19:40 UTC | |
|
Re: First code - Factors
by TomDLux (Vicar) on Sep 22, 2010 at 14:45 UTC | |
|
Re: First code - Factors
by mabeuf (Novice) on Sep 23, 2010 at 10:38 UTC |