code cleanup with explicit readline loop
[minime.git] / termimg
diff --git a/termimg b/termimg
index 2545c9bf388796329e17c7009a26c90240fb9319..6599b3b743dc20f8bb50a63dd4f9b7671ec8d31f 100755 (executable)
--- a/termimg
+++ b/termimg
@@ -1,10 +1,12 @@
 #!/bin/sh
 convert -compress none -resize 66x23 - pgm:- |
-perl -nE '
-$_ eq "P2\n" or die "ascii pgm input required\n" if $. == 1;
-next if $. <= 3;
+perl -e '
+<> eq "P2\n" or die "ascii pgm input required\n";
+<>; <>;  # ignore depth, dimensions
 
-state @ch = split //, " .oO@";
-print $ch[ $_ / 256 * @ch ] for /\d+/g;
-print $/;
+my @ch = split //, " .oO@";
+while (<>) {
+       print $ch[ $_ * @ch >> 8 ] for /\d+/g;
+       print $/;
+}
 '