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"; } }
In reply to First code - Factors by mabeuf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |