1
1
Fork 0

added two perl learing scripts

This commit is contained in:
david 2013-06-20 15:01:38 +02:00
parent 46c47c72e9
commit d3b7036987
2 changed files with 92 additions and 0 deletions

40
prime.pl Executable file
View File

@ -0,0 +1,40 @@
#!/usr/bin/env perl
# prime number calculation
# author: david@socialnerds.org
my $num = 3;
print "highest prime number: ";
chomp(my $maxnum = <STDIN>);
my $count = 2;
print "2\n3\n";
while ( $num <= $maxnum )
{
$i=3;
while ( $i <= int($num**(1/2)+1) )
{
if ( $i != 1 && $i < $num && $i%2 != 0 )
{
if ( $num % $i != 0 ) {
$probably = "true"
} else {
$probably = "false";
last;
}
}
$i += 2;
}
if ( $probably eq "true" )
{
print "$num\n";
$count++;
}
$num += 2;
}
print "prime number count: $count\n";

52
reference.pl Executable file
View File

@ -0,0 +1,52 @@
#!/usr/bin/env perl
use 5.010;
my $var = 5*5;
chomp(my $input = <STDIN>);
$var *= $input;
if ( $var == 100 )
{
say $var;
}
else
{
say "it is not 100";
}
$is_true = $var == 100;
if ( ! $is_true )
{
say "not true";
}
else
{
say "true";
}
my $zaehler=0;
while ($zaehler <= 5)
{
say "der zähler steht jetzt auf $zaehler";
$zaehler += 1;
}
chomp(my $input2 = <STDIN>);
if ( defined($input2) )
{
say "eingabe lautet: $input2";
}
else
{
say "keine eingabe verfügbar";
}
#umfang berechnung
print "bitte radius für umfangberechnung angeben: ";
chomp(my $radius = <STDIN>);
my $umfang = $radius *= 2*3.141592654;
say "umfang beträgt: $umfang";