From ChekMate Security Group
#!/usr/bin/perl
#todo.pl
#1.2
# Copyright (C) 2006 Joshua D. Abraham (jabra@ccs.neu.edu)
#
# This program is released under the terms of the GNU General Public License
# (GPL), which is distributed with this software in the file "COPYING".
# The GPL specifies the terms under which users may copy and use this software.
#
#
# Name: (c) Josh Abraham
# Date: Decemeber 1, 2004
# Purpose: script that keeps track of items on a todo list
use strict;
use warnings;
use IO::All;
my $todo="/home/jabra/svn/misc/todo";
my $count=0;
my @lines = io($todo)->slurp;
foreach (@lines){
next if /^X\#/;
$count++ if /^\#/;
}
print "ToDo $count items \n";
while (1){
my @lines = io($todo)->slurp;
print << 'END';
* * * * * * * * * * * * * * * * * * *
* A)dd Item to ToDo List *
* R)emove Item from ToDo List *
* L)ist Items on the ToDo List *
* C)lean ToDo List *
* Q)uit *
* * * * * * * * * * * * * * * * * * *
END
my $menu = <STDIN>;
chomp($menu);
&add_item if ($menu eq 'a' || $menu eq 'A');
&remove_item if ($menu eq 'r' || $menu eq 'R');
&show_items if ($menu eq 'l' || $menu eq 'L');
&clean if ($menu eq 'c' || $menu eq 'C');
&quit if ($menu eq 'q' || $menu eq 'Q');
}
sub show_items{
my $count=0;
my @lines = io($todo)->slurp;
my $line_num=1;
foreach (@lines){
next if /^X\#/ ;
if ($_ =~ /^\#/){
print "$line_num $_";
$line_num++
}
}
}
sub clean{
my $line_num=1;
foreach (@lines){
next if /^\#/;
next unless /^X\#/;
$_="";
$line_num++;
}
io($todo)->print(@lines);
}
sub remove_item{
print "Enter the number of item you wish to remove: ";
my $remove_item=<STDIN>;
chomp($remove_item);
my $line_num=1;
foreach (@lines){
next if /^X\#/;
next unless /^\#/;
if ($remove_item == $line_num) {
$_ = "X" . $_;
}
$line_num++;
}
io($todo)->print(@lines);
}
sub add_item{
my $count=0;
my @lines = io($todo)->slurp;
print "Enter the item you wish to add\n";
my $add_item=<STDIN>;
$add_item = '#' .' '. $add_item ;
$add_item >> io($todo);
}
sub quit{
exit;
}