#!/usr/local/bin/perl -w use strict; use Getopt::Std; getopts('hla:d:v:'); our($opt_h, $opt_a, $opt_d, $opt_v, $opt_l); my $jjfile = '/home/yourdir/data/jobjardb'; my $sep = '%%'; my $numsep = ') '; my $escsep = '\) '; # dammit. &usage if ($opt_h); # Read job jar file open(JAR,$jjfile) || die "can't open $jjfile: $!"; my @jar; { local $/ = $sep; @jar = map {s/^\s*//s;$_;} ; chomp @jar; } close(JAR); if ($opt_a) { my $nextnum = 1; if (defined $jar[-1]) { my ($lastnum) = ($jar[-1] =~ /^(\d+)/); $nextnum = $lastnum + 1; } open(JAR,">>$jjfile") || die "can't open $jjfile: $!"; if ((stat($jjfile))[7]) { print JAR "$sep\n"; } print JAR "$nextnum$numsep$opt_a\n"; close(JAR); print "Added: $nextnum$numsep$opt_a\n"; } elsif ($opt_d) { my @newjar; for my $job (@jar) { push(@newjar, $job) unless (&match_job_num($job, $opt_d)); chomp $job; print "Deleted: $job\n" if (&match_job_num($job, $opt_d)); } open(JAR,">$jjfile") || die "can't open $jjfile: $!"; print JAR join("$sep\n", @newjar); close(JAR); } elsif ($opt_v) { for my $job (@jar) { print $job if (&match_job_num($job, $opt_v)); } } elsif ($opt_l) { for my $job (@jar) { print "$job\n"; } } else { print $jar[rand(@jar)]."\n"; } ##### sub match_job_num { my ($job, $num) = @_; return unless ($num =~ /^\d+$/); return ($job=~/^$num$escsep/s)?1:0; } sub usage { print <