aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <matt@matthewlemon.com>2022-09-13 16:30:37 +0100
committerMatthew Lemon <matt@matthewlemon.com>2022-09-13 16:30:37 +0100
commitd84c321b74596ebeaed2ab504fd61d9e6899688e (patch)
tree4d47ff949879eaf59faf52191486f17296eed538
parentb74b3d849f8aea3f9572e15a66c8eada170970c3 (diff)
parent6b03ad8467e3d8eb300a5871da991763aa88e9fe (diff)
Merge branch 'master' of github.com:yulqen/perlscripts
-rw-r--r--writing_tools/random_line.pl42
1 files changed, 42 insertions, 0 deletions
diff --git a/writing_tools/random_line.pl b/writing_tools/random_line.pl
new file mode 100644
index 0000000..e85360f
--- /dev/null
+++ b/writing_tools/random_line.pl
@@ -0,0 +1,42 @@
+use strict;
+use warnings;
+use English;
+use Regexp::Common qw(URI);
+use feature qw(say);
+
+# How to read each file in a directory $dir
+
+my $numargs = $#ARGV + 1;
+
+if ($numargs != 1) {
+ say "Pass a search term. All lines in the journal will be matched and URLs quoted will be extracted.";
+ exit;
+}
+
+
+my @targetlines;
+my $searchterm = $ARGV[0];
+my @urls;
+
+my $dir = '/home/lemon/Notes/journal';
+foreach my $f (glob("$dir/*.md")) {
+ # printf "%s\n", $f;
+ open my $fh, "<", $f or die "Cannot open that file '$f': $OS_ERROR";
+ while (<$fh>) {
+ if ($_ =~ m/$searchterm/) {
+ # printf " %s", $_;
+ push @targetlines, $_;
+ }
+ }
+ close $fh or die "can't read close file '$f': $OS_ERROR";
+}
+
+foreach my $line (@targetlines) {
+ # if ($line =~ /(http.*$)/) {
+ if ($line =~ m/$RE{URI}{HTTP}{-scheme => qr<https?>}{-keep}/) {
+ my$t = $1;
+ $t =~ s/\.$//; # remove the fullstop if it has one at the end
+ print "Saving: $t\n";
+ push @urls => $t
+ }
+}