Created
May 11, 2020 04:01
-
-
Save caasi/938fcd1ebe600735cfee9dc6a248545f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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