Created
          April 20, 2013 16:53 
        
      - 
      
- 
        Save davorg/5426617 to your computer and use it in GitHub Desktop. 
    Simple prime checker
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/usr/bin/perl | |
| use warnings; | |
| use strict; | |
| while(<DATA>) { | |
| chomp; | |
| my $flag = 1; | |
| foreach my $i (2 .. sqrt($_)) { | |
| unless ($_ % $i) { | |
| $flag = 0; | |
| last; | |
| } | |
| } | |
| print "Number $_ "; | |
| if ($flag) { | |
| print "prime"; | |
| } else { | |
| print "not prime"; | |
| } | |
| print "\n"; | |
| } | |
| __END__ | |
| 0 | |
| 2 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 14 | |
| 17 | |
| 18 | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment