Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

modify perl script for GTD and VIM

Status
Not open for further replies.

ezichko

Programmer
Joined
Mar 19, 2007
Messages
2
Location
ES
hi:

i have this script which reads a txt file and outputs a list of tasks grouped by context.

it was made to work with emacs org mode but i want to use vim instead.

how should i change it to scan all lines of text and group context that appear as @work @home etc.

for example if my text file is

project: website 123
create logo @work
call client @phone

project conquer world
research @computer
call friends @phone

then the script outputs

@computer:
research

@phone:
call client
call friends

you get the idea.

the script:

---------------

use strict;
use warnings;

# Read an org file and create lists by context (tag)
# Written by Charles Cave charles.cave (at) gmail.com
# 28th June 2006

my $orgfile = shift;
defined($orgfile) or die "syntax is orghip.pl orgfilename\n";

open(my $org, "<", $orgfile) or die "Cannot open $orgfile\n";
my %lists = ();
my $now = localtime();

while (<$org>) {
my $line = $_;
chomp($line);
if ($line =~ /^\*+\s*(.*?):([A-Za-z]+):/) {
my $hdng = "$1";
my $tag = $2;
if ( defined($lists{$tag}) ) {
$lists{$tag} = $lists{$tag}."\n".$hdng;
} else {
$lists{$tag} = $hdng;
}
}
}

print "Date Printed: $now\n";

process_context("PROJECT");

process_context("OFFICE");
process_context("HOME");
process_context("COMPUTER");
process_context("DVD");
process_context("READING");

# print any remaining contexts
foreach my $key (sort keys %lists) {
process_context($key);
}

sub process_context {
my $context = shift;
print "\n\n$context:\n";
foreach my $item( split(/\n/, $lists{$context}) ) {
print "[ ] $item\n";
}
delete $lists{$context};
}
 
what have you tried?

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
this:
if ($line =~ /^\s*(.*?)@([A-Za-z]+)/) {

it will output lines that have @whatever and group them nicely.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top