#!/usr/bin/perl # quitmeter.pl - a perl script to help me quit smoking # Copyright (C) 2000-2003 Daniel Lowe # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # or at http://www.fsf.org/licenses/gpl.html use POSIX; $QUIT_MONTH = 0; $QUIT_DAY = 0; $QUIT_YEAR = 0; $QUIT_HOUR = 0; $QUIT_MINUTE = 0; $SMOKES_PER_DAY = 0; $PRICE_PER_PACK = 0; # ------------------------- Configuration ends ------------------------------- $quit_time = mktime( $QUIT_SECOND,$QUIT_MINUTE,$QUIT_HOUR,$QUIT_DAY,$QUIT_MONTH - 1,$QUIT_YEAR - 1900,0,0,-1 ); $passed_time = time() - $quit_time; $not_smoked = floor( $passed_time * $SMOKES_PER_DAY / 86400 ); $time_to_freedom = 259200 - $passed_time; print "Time passed:" . show_time( $passed_time ) . "\n"; if ( $time_to_freedom > 0 ) { print "Time until worst passes:" . show_time( $time_to_freedom ) . "\n"; } print "Cigarettes not smoked: $not_smoked\n"; printf "Money saved: \$%.02f\n", ( $not_smoked * $PRICE_PER_PACK ) / 20; $more_time = $not_smoked * 6 * 60; print "Life gained: " . show_time( $more_time ) . "\n"; end; sub show_time { my $time = shift; my $weeks,$days,$hours,$minutes; my $result; return "" if $time <= 0; $weeks = floor( $time / 604800 ); $time -= $weeks * 604800; $days = floor( $time / 86400 ); $time -= $days * 86400; $hours = floor( $time / 3600 ); $time -= $hours * 3600; $minutes = floor( $time / 60 ); $time -= $minutes * 60; $result .= " $weeks week" . ( ( $weeks == 1 ) ? "":"s" ) if $weeks > 0; $result .= " $days day" . ( ( $days == 1 ) ? "":"s" ) if $days > 0; $result .= " $hours hour" . ( ( $hours == 1 ) ? "":"s" ) if $hours > 0; $result .= " $minutes minute" .( ( $minutes == 1 ) ? "":"s" ) if $minutes > 0; return $result; }