You indicated that you are printing bytes (: raw), but that is not the case.
$ perl -we'
open(my $fh, ">:raw", "file") or die $!;
for (0..258) {
print "$_\n";
print $fh chr($_);
}
'
...
249
250
251
252
253
254
255
256
Wide character in print at -e line 5.
257
Wide character in print at -e line 5.
258
Wide character in print at -e line 5.
To “cancel printing”, you just need to check that what you print does not contain bytes.
die if $to_print =~ /[^\x00-\xFF]/;
source
share