Using warnings is a good start, but the rest of the strictures mantra is to use strict. Personally I like a little more white space around the place and have tuned Perl::Tidy to do it the way I like it.
You should avoid overloading variable names. You use both $int and @int. In some cases that can lead to very subtle and hard to find bugs. In fact for this code you don't need the array at all, just plonk the range straight into the for loop list.
Making those few adjustments gives:
#!/usr/bin/perl use strict; use warnings; print "Type number you want factorised: \n"; chomp (my $no = <STDIN>); print "The factors of $no are: \n"; foreach my $int (1 .. $no / 2) { my $div = $no / $int; my $remainder = $no % $int; if ($remainder == 0) { print "$div\n"; } }
In reply to Re: First code - Factors
by GrandFather
in thread First code - Factors
by mabeuf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |