Perl Stop Print if Wide Characters Error
perl
Solution
You specified you're printing bytes (:raw), but you're not.
$ 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 the print", you simply have to check that what you print doesn't contains non-bytes.
die if $to_print =~ /[^\x00-\xFF]/;
Problem
I have a simple print script ``` my $pdf_data = $agent->content; open my $ofh, '>:raw', "test.pdf" or die "Could not write: $!"; print {$ofh} $pdf_data; close $ofh; ``` Sometimes I get the "Wide character warning", I know why I receive this and would like to be able to cancel the print instead of printing a corrupted fail. Something like ``` if(wideCharWarning) { delete "test.pdf" } else{ print {$ofh} $pdf_data; } ```