#!/usr/bin/perl use strict; #randomly outputs one line from a file srand; my $in = \*STDIN; if( defined $ARGV[0] ){ open $in, "$ARGV[0]" or die "Error opening file $ARGV[0]: $!"; } my @lines = <$in>; my $line = $lines[int( rand() * scalar(@lines) )]; close IN; print "$line";