Skip to content

Instantly share code, notes, and snippets.

@caasi
Created May 11, 2020 04:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caasi/938fcd1ebe600735cfee9dc6a248545f to your computer and use it in GitHub Desktop.
Save caasi/938fcd1ebe600735cfee9dc6a248545f to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
my @articles;
my $cur_article = 0;
if(@ARGV != 1){
open DIARY, "<./.note" or die;
while(<DIARY>){
exit @diary if(/EOD/);
print;
}
# print "usage: diary.pl yyyyMMMdd\n".
# "use -l to show all exist diary title\n";
# exit;
}
if($ARGV[0] eq '-l'){
open DIARY, "<./.note" or die;
while(<DIARY>){ print if /^200/ }
close DIARY;
exit;
}
if($ARGV[0] eq '-r'){
open DIARY, "<./.note" or die;
while(<DIARY>)
{
$articles[$cur_article] .= $_;
$cur_article++ if /EOD/;
}
close DIARY;
print foreach reverse @articles;
exit;
}
print "*" x 80,"\n";
open DIARY, "<./.note" or die;
while(<DIARY>){
if(/$ARGV[0]/){
$found = 1;
$flag = 1;
}
if($flag){
if(/EOD/){
print @diary;
$flag = 0;
}else{
push(@diary, $_);
}
}
}
if(!$found){
print "cann't find diary of $ARGV[0]\n";
}
close DIARY;
print "*" x 80,"\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment