Skip to content

Instantly share code, notes, and snippets.

@andysc
Created October 31, 2012 19:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andysc/3989186 to your computer and use it in GitHub Desktop.
Save andysc/3989186 to your computer and use it in GitHub Desktop.
wrap input to 32 columns, breaking on spaces
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";
}
@andysc
Copy link
Author

andysc commented Oct 31, 2012

just the thing for splitting up text being live-streamed to one of little dinky microprinters!

@andysc
Copy link
Author

andysc commented Oct 31, 2012

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