05/5/13

Perl

================================
bday-perltest
================================

#!/usr/bin/perl
#
# Program to show the next birthdays from a listfile

#parameter
$nextbirthdays = 25;

#Datum bestimmen
($sek, $min, $std, $tag, $mon, $jahr) = localtime(time);
$jahr = $jahr + 1900;
$mon++;
print “$tag $mon $jahr \n”;

$file = ‘birthday.ini’; # Filename zuweisen
open(INFO, $file); # File öffnen

@lines = <INFO>; # alle Zeilen einlesen
$length = @lines; # bestimme Array-Länge

# for ($i = 0; $i < $length; ++$i)

$i = 0;
$count = 0;

while ($count < $nextbirthdays)
{

@record = split(/ /, $lines[$i]); # get day+month
$dayMonth = @record[0]; # get day+month

$birthday = substr($dayMonth, 0, 2); # get birthday
$birthmonth = substr($dayMonth, 3, 2); # get birthmonth

if(
($birthmonth > $mon)
or ( ($birthmonth == $mon) and ($birthday >= $tag) )
or ($count > 0)
)
{
print $lines[$i]; # Zeilen ausgeben
$count++;
# print “count $count\n”;
# print “$i\n”;

}
# print “$i\n”;

if($i >= $length){
$i = 0;
}
else{
$i++;
}
}

close(INFO); # File schliessen

================================
birthday.ini
================================
03.01. 1952 Ma Muster
10.01. 1975 Else
15.01. 1925 Billy Horst
16.01. 0000 Max Molch
24.01. 1978 Klaus Strolch
31.01. 1973 Klaas Clever