simplify or clean up example scriptlets
authorMischa POSLAWSKY <perl@shiar.org>
Sat, 12 Nov 2022 23:37:24 +0000 (00:37 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Fri, 18 Nov 2022 00:25:46 +0000 (01:25 +0100)
barcat
t/examples.t

diff --git a/barcat b/barcat
index 35ef3b3d314a7117f02f886aa717076671744868..cc128a06fd8815f34f910c932cce36a94e789118 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -589,7 +589,7 @@ Compare file sizes (with human-readable numbers):
 
 Memory usage of user processes with long names truncated:
 
-    ps xo %mem,pid,cmd | barcat -l40
+    ps xo rss,pid,cmd | barcat -l40
 
 Monitor network latency from prefixed results:
 
@@ -607,7 +607,7 @@ Letter frequencies in text files:
 
 Number of HTTP requests per day:
 
-    cat log/access.log | cut -d\  -f4 | cut -d: -f1 | uniq -c | barcat
+    cat httpd/access.log | cut -d\  -f4 | cut -d: -f1 | uniq -c | barcat
 
 Any kind of database query with counts, preserving returned alignment:
 
@@ -616,7 +616,7 @@ Any kind of database query with counts, preserving returned alignment:
 
 In PostgreSQL from within the client:
 
-       postgres=> SELECT sin(generate_series(0, 3, .1)) \g |barcat
+    > SELECT sin(generate_series(0, 3, .1)) \g |barcat
 
 Earthquakes worldwide magnitude 1+ in the last 24 hours:
 
@@ -626,10 +626,7 @@ Earthquakes worldwide magnitude 1+ in the last 24 hours:
 External datasets, like movies per year:
 
     curl https://github.com/prust/wikipedia-movie-data/raw/master/movies.json -L |
-    perl -054 -nlE 'say if s/^"year"://' | uniq -c | barcat
-
-But please get I<jq> to process JSON
-and replace the manual selection by C<< jq '.[].year' >>.
+    jq .[].year | uniq -c | barcat
 
 Pokémon height comparison:
 
@@ -640,13 +637,13 @@ USD/EUR exchange rate from CSV provided by the ECB:
 
     curl https://sdw.ecb.europa.eu/export.do \
          -Gd 'node=SEARCHRESULTS&q=EXR.D.USD.EUR.SP00.A&exportType=csv' |
-    grep '^[12]' | barcat -f',\K' --value-length=7
+    barcat -f',\K' --value-length=7
 
 Total population history in XML from the World Bank:
 
-    curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL -L |
-    xmllint --xpath '//*[local-name()="date" or local-name()="value"]' - |
-    sed -r 's,</wb:value>,\n,g; s,(<[^>]+>)+, ,g' | barcat -f1 -H
+    curl http://api.worldbank.org/v2/country/1W/indicator/SP.POP.TOTL |
+    xmlstarlet sel -t -m '*/*' -v wb:date -o ' ' -v wb:value -n |
+    barcat -f1 -H
 
 And of course various Git statistics, such commit count by year:
 
index 1af87e5fa5a368e799f589d5f6a2393f5d67dc73..c5648ad06c1b2bec403a211146811662282b1f7e 100755 (executable)
@@ -13,7 +13,7 @@ use Test::More;
 my %CMDARGS = (
        ping => '-c 1',
        curl => '-sS',
-       'cat \Klog/' => '/var/log/apache2/',
+       'cat \Khttpd/' => '/var/log/apache2/',
 );
 
 my $filename = 'barcat';
@@ -22,9 +22,10 @@ open my $input, '<', $filename
 
 local $/ = "\n\n";
 while (readline $input) {
-       # find code snippets in the appropriate section
+       # find scriptlets in the appropriate section
        /^=head1 EXAMPLES/ ... /^=head1/ or next;
-       /^\h/ or next;
+       /^\h/ or next;  # indented code snippet
+       /\A\h*>/ and next;  # psql prompt
        chomp;
 
        # compose an identifier from significant parts