Shawn H Corey <shawnhco...@gmail.com> writes: > Harry Putnam wrote: >> What I'm working on will eventually be a script that reads an `events' >> file and lets me know about events I've entered there. It's my own >> primitive but hopefully effective calendar reminder type of tool. >> >> The format of entries look like this: >> >> cat ~/.events >> >> ev 100411 4 >> Wash behind ears >> ev >> >> ev 100421 4 >> Avoid a beating by taking out the garbage >> this evening. >> ev >> >> [...] >> >> The multidigit numbers represents YYMMDD, > > if( my ( $year, $mnth, $mday, $extra ) = $line =~ m{ \A \s* ev \s* > (\d\d)(\d\d)(\d\d) \s* (\d+) \s* \Z }msx ){ > # process event > }else{ > # do something else > }
Yikes, I'll be a week with perlre to get even close to following that. In fact I don't really understand whats happening there at all. Also it doesn't appear to work with the data I posted unless the $extra is present, and that is supposed to be up to the ~/.events author. But that may be something I've done to it. I maid no attempt to actually do the kind of processing done in the real script. #!/usr/local/bin/perl use strict; use warnings; my $file = '/home/reader/.events'; open my $fh, '<', $file or die "Can't open $file: $!"; while (<$fh>) { if ( my ( $year, $mnth, $mday, $extra ) = $_ =~ m{ \A \s* ev \s* (\d\d)(\d\d)(\d\d) \s* (\d+) \s* \Z }msx ) { # process event print "year=<$year>, mnth=<$mnth>, mday=<$mday>\n"; if ($extra) { print "extra=<$extra>\n"; } } else { print "This is the else part\n"; # do something else } } close $fh; It only hits where the $extra Numeral is present in this data: ------- --------- ---=--- --------- -------- cat ~/.events ev 100326 Check Harry's bank account shoot your self if its less than $500 ev ev 100409 6 send state tax payment by Ap 15th ev ev 100604 Newsguy account expires 100607 ev ev 100423 3 my Dr. appt is monday Ap 23 ev > How well the regex works depends on whether the syntax is followed > correctly. Since you designed the syntax, you're the one who must > enforce it. :) Yeah, there is that.. hehe. I set an abbrev for emacs that expands hpev<spc> to: ev YYMMDD X ev Where YYMMDD is todays date, and is mainly there to edit. The cursor lands where the X is. User is expected to edit the date and add an extra numeral if so desired and of course, fill in whatever the event is. To me this is much handier and faster than any of the gui calendar or appointment apps I've seen. > Perhaps you should consider writing the data in XML: > > <ev year="2010" month="04" mday="11" extra="4"> > Wash behind ears > </ev> > > <ev year="2010" month="04" mday="21" extra="4"> > Avoid a beating by taking out the garbage > this evening. > </ev> > > There are tools like xmllint(1) and tidy > <http://www.w3.org/People/Raggett/tidy/> that can verify the syntax is > correct. And a whole mess of XML parsers in CPAN. I guess you're thinking of some automated way to enter the necessary info eh? I mean it looks like a heck of a lot more typing.. Or a much more complex abbrev expansion. Then finding the place to start editing would be more messing around too. Plus it would require specific perl modules to be present. I'm not sure I get why I'd want to do that rather than a more simple and primitive script that any basic perl installation will handle. The format I came up with is easily verifiable in a glance. Currently I was trying to use the closing `ev' on a line by itself to trigger what ever action is required. I'm thinking now about reworking some of the script so that the last line `ev$' can be dropped too. Using the next `ev YYMMDD' pattern, or eof to trigger writing So the format would then be even easier to verify in a glance. ev YYMMDD body body ev YYMMDD 3 body [...] And of course the user would be expected to delete old events no longer needed as time goes on, so the file would hopefully never get too long and confusing. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/