[perltidy]
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Sat, 29 Oct 2011 21:49:21 +0200
changeset 3 1519d83aa83b
parent 2 22e93ecd595f
child 4 6a11b95c4904
[perltidy]
.perltidyrc
prime
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/.perltidyrc	Sat Oct 29 21:49:21 2011 +0200
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- a/prime	Sat Oct 29 21:48:44 2011 +0200
+++ b/prime	Sat Oct 29 21:49:21 2011 +0200
@@ -12,6 +12,7 @@
 my $ME = basename $0;
 
 if (not @ARGV) {
+
     # FIXME: be more verbose
     die "$ME: Sorry, need the number\n";
 }
@@ -25,7 +26,7 @@
 my @primes = ();
 
 #for each element in array divisors
-foreach my $div (@divisors) { #same element in div
+foreach my $div (@divisors) {    #same element in div
 
     #find all divisors of div and save in subprimes
     my @subprimes = findDivisors($div);
@@ -33,7 +34,7 @@
     #determine length of subprimes and save in noOfDivisors
     my $noOfDivisors = scalar(@subprimes);
 
-    if ($noOfDivisors == 0) {@primes = (@primes, $div); }
+    if ($noOfDivisors == 0) { @primes = (@primes, $div); }
 }
 
 #print"Die Teile von $number sind: ".join(", ", @divisors)."\n";
@@ -43,13 +44,14 @@
 @primes = factorize($number, @primes);
 
 if (@primes) {
-    print join("*", @primes), "\n"; 
+    print join("*", @primes), "\n";
 }
 else {
+
     #print STDERR "Sorry, $number is prime itself!\n";
     warn "Sorry, $number is prime itself\n!";
 }
-    
+
 exit;
 
 #### SUBROUTINES #####
@@ -57,30 +59,31 @@
 sub findDivisors {
     my $i = 2;
     my $m = $_[0];
-    
+
     my @divisors = ();
-    
+
     while ($i < $m) {
-	if($m % $i ==0){
-	    @divisors = (@divisors, $i);
-	}
-	$i++;
+        if ($m % $i == 0) {
+            @divisors = (@divisors, $i);
+        }
+        $i++;
     }
     return @divisors;
 }
 
 sub factorize {
     my $current = shift @_;
-    my @primes = @_;
+    my @primes  = @_;
 
     my @result;
     foreach my $prime (@primes) {
-	while (0 == ($current % $prime)) {
-	    push @result, $prime;
-	    $current = $current / $prime;
-	    # better:
-	    # $current /= $prime;
-	}
+        while (0 == ($current % $prime)) {
+            push @result, $prime;
+            $current = $current / $prime;
+
+            # better:
+            # $current /= $prime;
+        }
     }
 
     return @result;