#!/usr/bin/perl # use strict; use warnings; use Data::Dumper::Simple; open my $fout, '>', '/var/www/paperlined.org/tmp/compatible_DeWalt_drills.md' or die $!; print $fout <<'EOF'; EOF my @models_textlines = ql( <<'EOF' ); DCD785 notsold DCD790 notsold # The closest is: DCD794B DCF885 sold impactdriver DCF895 notsold DCD995 notsold DCD996B sold hammerdrill DCD985 notsold DCF826 notsold DC825 notsold DC827 notsold DCF886 notsold DCF887B sold impactdriver DCD970 notsold DCD996B sold hammerdrill EOF #die Dumper @models_textlines; # parse @models_textlines into @models my @models; foreach my $line (@models_textlines) { my @tokens = split ' ', $line; my %hash = ( model => $tokens[0], ); foreach my $passthrough (grep /^(not)?sold$/, @tokens) { $hash{$passthrough} = 1 } push @models, \%hash; } #die Dumper @models; select $fout; foreach my $hash (@models) { my $model = $hash->{model}; if ($hash->{notsold}) { print "* $model   "; } else { print "* $model   "; } print "[[amazon]](https://www.amazon.com/s?k=dewalt+%22$model%22) "; print "[[dewalt.com]](https://www.google.com/search?q=site:dewalt.com+$model) "; print " "; $hash->{sold} && print "(sold) "; $hash->{notsold} && print "(not sold) "; print " "; print "\n"; } # Like qw[...], but breaks on lines instead. Comments (hash symbol) are ignored, and can occur anywhere in a line. # From https://gist.github.com/DeeNewcum/8faaf6512a1cea04f63d31a9ab4abe81 sub ql {map{s/\s+#.*|#.*|^\s+|\s+$//gs;$_}split/[\n\r]+/,shift}