#!/usr/bin/perl use strict; use warnings; my $file = 'lwall-quotes.txt'; # http://www.cpan.org/misc/lwall-quotes.txt.gz my $recSep = "%%$/"; # input record separator in dieser Datei print zufallsEintrag($file, $recSep); ############################################################################### sub zufallsEintrag { $file = shift; local $/ = (shift or $/); open my $txtFH, "<", $file or die $!; my $entryCnt; $entryCnt++ while <$txtFH>; my $selEntry = int(rand($entryCnt))+1; my $entry; seek $txtFH,0,0; # wieder an den Anfang $.=0; # wird mit seek nicht auf 0 zurückgesetzt while ($entry = <$txtFH>) { last if $. == $selEntry; } close $txtFH or die $!; chomp($entry); return $entry; }