#!/usr/athena/bin/perl # Zsig random blah. Written by Joshua Pollack for Jessie Lowell. use strict; my $zsig_file = $ENV{'HOME'} . "/Private/zsigs"; my $delimeter = "."; my $last_file = "/tmp/" . $ENV{'USER'} . "-last-zsig-idx"; ###################################################################### my $zsigs = []; open (ZSIGS, $zsig_file) or die "Can't open zsig file ($zsig_file): $!"; my $current_zsig = ""; while (my $line = ) { chomp ($line); unless ($line eq $delimeter) { # unless its the delimiter... $current_zsig .= $line . "\n"; # append to the current reading zsig } else { # it is the delimeter, so skip it and push the read zsig onto the list push (@{$zsigs}, $current_zsig); $current_zsig = ""; } } close (ZSIGS); my $last_idx = -1; if ((-r $last_file) and open (LASTFILE, $last_file)) { chomp ($last_idx = ); close (LASTFILE); } my $random_idx = $last_idx; $random_idx = int (rand ($#{$zsigs} + 1)) while ($random_idx == $last_idx); if (open (LASTFILE, '>', $last_file)) { print LASTFILE $random_idx, "\n"; close (LASTFILE); } print $zsigs->[$random_idx];