Created
October 31, 2012 19:12
-
-
Save andysc/3989186 to your computer and use it in GitHub Desktop.
wrap input to 32 columns, breaking on spaces
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
while (<>) | |
{ | |
chomp; | |
$line = $_; | |
while (length($line) > 32) | |
{ | |
$bit = substr($line,0,32); | |
$space = rindex($bit," "); | |
if ($space == -1) | |
{ | |
print $bit,"\n"; | |
$line = substr($line,32); | |
} | |
else | |
{ | |
print substr($bit,0,$space),"\n"; | |
$line = substr($line,$space+1); | |
} | |
} | |
print $line,"\n"; | |
} |
to stream an MQTT topic to a microprinter via this wrapping code, try:
mosquitto_sub -t printer | perl perl_wrap.pl >> /dev/ttyUSB0
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
just the thing for splitting up text being live-streamed to one of little dinky microprinters!