Schrift
Wiki:Tipp zum Debugging: use Data::Dumper; local $Data::Dumper::Useqq = 1; print Dumper \@var;
[thread]4543[/thread]

kleiner Terminplaner

Leser: 2


<< |< 1 2 >| >> 18 Einträge, 2 Seiten
renee
 2005-08-09 20:38
#40409 #40409
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Du benutzt CPAN:Date::Calc aber dann rechnest Du den "Countdown" selbst aus. Date::Calc hat die Methode Delta_DHMS. Das system("clear"); funktioniert aber nur auf Linux.

Es wäre schön, wenn das Programm auch Wiki:use strict;-sicher wäre...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
ptk
 2005-08-09 22:03
#40410 #40410
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Das Programm verwendet immer die Datei ".termine" im aktuellen Verzeichnis. Ein definiertes Verzeichnis (z.B. $ENV{HOME}/.termine bei Unix) waere wahrscheinlich besser. Evtl. auch eine Option -f, um eine andere Datei anzugeben.

Statt system("clear") wuerde ich bevorzugt Term::Cap verwenden. Z.B. so:
Code: (dl )
1
2
3
4
5
6
7
8
9
my $clearchr;
if (eval { require Term::Cap }) {
my $terminal = Tgetent Term::Cap { TERM => undef };
$clearchr = $terminal->Tputs("cl");
}
if ($clearchr eq '') {
# XXX MSWin32: use cls instead?
$clearchr = `clear`;
}

Mit print $clearchr wuerde man den Bildschirm loeschen.
Strat
 2005-08-10 14:17
#40411 #40411
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
anscheinend gibt es probleme mit tabulatoren...
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
pKai
 2005-08-10 15:07
#40412 #40412
User since
2005-02-18
357 Artikel
BenutzerIn
[default_avatar]
Quote
Name "main::gmt" used only once: possible typo...
bezogen auf
Code: (dl )
my ($y,$m,$d,$h,$min,$s) = Today_and_Now([$gmt]);
gerufen von sub printday.
Wohl ein Artefakt aus der perldoc Date::Calc wo dieses $gmt so auftaucht.
I sense a soul in search of answers.
ptk
 2005-08-10 15:57
#40413 #40413
User since
2003-11-28
3645 Artikel
ModeratorIn
[default_avatar]
Wenn derjenige seinen Code nicht veroeffentlicht, dann ist es mir egal. Wenn er
Code: (dl )
1
2
3
# Local variables:
# tab-width: 4
# End.
in seine Datei schreibt, dann kann ich wenigstens die Datei im Emacs richtig lesen, aber man muesste das gleiche fuer den vi und alle anderen Editoren machen.

Sich vorzunehmen, Leerzeichen und Tabs nicht zu mischen, ist schoen gedacht, aber was ist, wenn die Datei von jemand anders editiert wird, der diese (private!) Konvention nicht kennt?
Strat
 2005-08-10 16:06
#40414 #40414
User since
2003-08-04
5246 Artikel
ModeratorIn
[Homepage] [default_avatar]
[quote=ptk,10.08.2005, 13:57]Wenn derjenige seinen Code nicht veroeffentlicht, dann ist es mir egal. Wenn er
Code: (dl )
1
2
3
# Local variables:
# tab-width: 4
# End.
in seine Datei schreibt, dann kann ich wenigstens die Datei im Emacs richtig lesen, aber man muesste das gleiche fuer den vi und alle anderen Editoren machen.

Sich vorzunehmen, Leerzeichen und Tabs nicht zu mischen, ist schoen gedacht, aber was ist, wenn die Datei von jemand anders editiert wird, der diese (private!) Konvention nicht kennt?[/quote]
da faende ich es genial, wenn der editor beim speichern alle fuehrenden tabs durch leerzeichen ersetzen wuerde, und zwar durch so viele, wie man eingestellt hat (oder alternativ: nur tabs zum einruecken verwenden, dann ist es egal)
perl -le "s::*erlco'unaty.'.dk':e,y;*kn:ai;penmic;;print"
http://www.fabiani.net/
Taulmarill
 2005-08-10 16:41
#40415 #40415
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
mein vim ist so eingestellt, er fügt also beim betätigen der tab taste 4 whitespaces ein. das ist im übrigen auch die empfehlung von perldoc perlstyle.
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
Taulmarill
 2005-08-11 15:28
#40416 #40416
User since
2004-02-19
1750 Artikel
BenutzerIn

user image
mein verweis auf perlstyle bezog sich auch nur auf die 4 spalten, nicht auf whitespaces. ob das einrücken von 4 spalten bei einem tab korrekt ist oder nicht, ist halt ansichtssache. du hast selbst weiter oben geschrieben, dass bei tabs eigendlich 8 spalten standart ist.
$_=unpack"B*",~pack"H*",$_ and y&1|0& |#&&print"$_\n"for@.=qw BFA2F7C39139F45F78
0A28104594444504400 0A2F107D54447DE7800 0A2110453444450500 73CF1045138445F4800 0
F3EF2044E3D17DE 8A08A0451412411 F3CF207DF41C79E 820A20451412414 83E93C4513D17D2B
Gast Gast
 2005-08-09 19:41
#40417 #40417
Hallo, ich habe einen kleinen Terminplaner geschrieben. Ich find ihn recht nett, aber mich interessiert eure Meinung. Was könnte man besser machen(sauberer Code, Komentare, ...). Hier der Code:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#! /usr/bin/perl -w

#Tue Aug 9 18:31:56 2005
#Sweet little appointment planer written by Robin Wenglewski <robin@wenglewski.de>
#please keep me up to date with changes on this programm. I know it's not perfect (nor is it my english) but
#I would be glad to hear suggestions for improvement

use Date::Calc qw(Mktime);
use Date::Calc qw(Today_and_Now);
use Getopt::Std;
use Time::localtime;
use Term::ReadKey;

#getting the options
my $optstring = 'nls:ad';
getopts("$optstring", \%opt ) or die "error with getopts";

#optional
if ($opt{a}) {$all='true';} else {$all='false';}

#what happens with which option
if ($opt{n}) {&new;}
elsif ($opt{l}) {&list;}
elsif ($opt{s}) {&search;}
elsif ($opt{d}) {&demon;}
else {&usage};


sub demon() {
open(IFILE,"<\.termine");
while(<IFILE>) {
#splitting the lines line up
my @parts=split("\:\:",$_);
#filtering invalid an past appoitments
if ($#parts!=2 || ($all eq 'false' && $parts[0]<(time))) {next;}
#with the next appoitment, start &countdown
if ($parts[0]>(time)) {&countdown(@parts); }}
close IFILE;}


sub printday() {
open(IFILEDAY,"<\.termine");
print "\n\nDay appointments:\n";
#getting the momentanious time
my ($y,$m,$d,$h,$min,$s) = Today_and_Now([$gmt]);
#etime is the time of the last second of that day
my $etime = Mktime($y,$m,$d,23,59,59);
while(<IFILEDAY>) {
my $line = $_;
my @parts=split("\:\:",$line);
#filter invalids
if ($#parts!=2 || ($all eq 'false' && ($parts[0]<=$_[0] || $parts[0]>=$etime))) {next;}
#print the rest
if ($parts[0]>(time)) {&printtermin($line); }}}
close IFILEDAY;

sub countdown() {
#getting the argument
my $line=$_;
my @parts=split("\:\:",$line);
#variable for a pressed key
my $key="";
#creating new process and saving the id in $pid
my $pid = fork();

# The Child-Prozess
if($pid == 0){
open(IFILE,"<\.termine");
while(1){
#clearing sceen
system("clear");
print(ctime(time)."\n");
#getting the remaining time
my $s = $parts[0]-(time);
my $d=0;
my $h=0;
my $m=0;
if ($s>=60) {

$tmp=$s % 60;

$m=($s-$tmp) / 60;

$s=$tmp;
if ($m>=60) {

$tmp=$m % 60;

$h=($m-$tmp) / 60;

$m=$tmp;
if ($h>=24) {

$tmp=$h % 24;

$d=($h-$tmp) / 24;

$h=$tmp;

}}}
#printing the remaining time
print ("\nnext appointment in $d Tagen $h\:$m\:$s\n");
#printing the coming appointment
print ("\ncoming appointment:\n\n");
&printtermin($line);
#print the rest of the appointments of that day
&printday($parts[0]);
#making sure that the whileloop doesn't take all resources
system("sleep 1");}
#Main Process
} else {
#when a key is pressed, you don't have to press also <return>
ReadMode "raw";
#as long as q isn't pressed
while(!($key eq "q")) {
open(TTY, "</dev/tty");
#waiting for a key stroke
$key = ReadKey 0, *TTY; }
#when q was pressed, Readmode back to normal
ReadMode "normal";
print "\n";
close IFILE;
#and killing the child process
kill 9,$pid;
#and exit the programm
exit;}}


sub search() {
open (IFILE,"<\.termine");
while(<IFILE>) {
#if the line contains the demanded string, print it
if($_ =~ /$opt{s}/i) {&printtermin($_);}}
close IFILE; }

sub list() {
open (IFILE,"< \.termine");
while(<IFILE>) {
&printtermin($_);}
close IFILE;
}

sub printtermin() {
#split up the given argument (it has to be a line)
@parts=split("\:\:",$_[0]);
#filter invalids
if ($#parts!=2 || ($all eq 'false' && $parts[0]<(time))) {return 1;}
#and print the appointment
print ctime($parts[0]).': '.$parts[1]."\n".$parts[2]; }


sub new() {
#get title and time
my $titel=$ARGV[2];
my $seks=&zeitumrechnung($ARGV[0],$ARGV[1]);
print "Please enter now further informations:\n";
$info=<STDIN>;
open(OFILE, ">> \.termine");
#print everything in file
print OFILE "$seks\:\:$titel\:\:$info";
close OFILE;
#arrange it
&arrange;
}


sub arrange() {
my @termine;
#open one input and one output file
open(IFILE,"< \.termine");
open(OFILE,"> \.termine.new");
while(<IFILE>) {
#split each line
@parts=split("\:\:",$_);
#and push it in termine (@parts should contain three variables)
push(@termine,@parts); }
close IFILE;
#now the real arrangement follows
for($i=0;$i<=$#termine-5;$i+=3) {
for ($j=$i+3;$j<=$#termine-2;$j+=3) {
if($termine[$i]>$termine[$j]) {

($termine[$i], $termine[$j]) = ($termine[$j], $termine[$i]);

($termine[$i+1], $termine[$j+1]) = ($termine[$j+1], $termine[$i+1]);

($termine[$i+2], $termine[$j+2]) = ($termine[$j+2], $termine[$i+2]); } }}
for($i=0;$i<=$#termine-2;$i+=3) {
#and here the termine array is printed back to a file
print OFILE "$termine[$i]\:\:$termine[$i+1]\:\:$termine[$i+2]"; }
close OFILE;
#now the new file substitutes the old one
system("mv -f .termine.new .termine");
}


sub zeitumrechnung() {
my $datum=$_[0];
my @datum=split('\.',$datum);
my $zeit=$_[1];
my @zeit=split(':',$zeit);
#make a $time format and return it
my $time = Mktime($datum[2],$datum[1],$datum[0],$zeit[0],$zeit[1],0);
return $time; }

sub usage() {
print "\nusage: apps.pl [command]
-l lists all coming appointments
-n [dd.mm.yyyy hh:mm NAME] creates an appointment to the given time under the name NAME
-s [PATTERN] looks through the coming appointments for the pattern
-d deamon (q=quit)

OPTIONAL
-a lists all\n\n"; }
renee
 2005-08-09 20:40
#40418 #40418
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Am Ende von printday() steht ein close FILEHANDLE, das sicherlich innerhalb der Methode stehen sollte. So wie es bei Dir im Code steht, ist es nämlich außerhalb der Methode...

Fehlerbehandlung wäre auch schön, z.B. wenn Du Dateien öffnest...
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/
<< |< 1 2 >| >> 18 Einträge, 2 Seiten



View all threads created 2005-08-09 20:38.