Tag Archives: perl

Perl PostScript::TextBlock Fix for ARRAY ref Error on line 57

While dealing with the hellishness of generating Postscript from scratch, I ran into an error using the PostScript::TextBlock module for Perl.  This seems to effect Ubuntu and I’m sure also Debian, when it next releases, unless this gets fixed.

The error message is:

Can't use string ("4") as an ARRAY ref while "strict refs in use at /usr/share/perl5/PostScript/TextBlock.pm line 57

Upon looking, I saw it’s using a peculiar old way of returning the number of elements of an array. Fortunately, this error is easily fixed by editing the TextBlock.pm file, heading to line 57 and changing:

return $#{@$self}+1;

to the much more readable:

return scalar @$self;

This works because when you return a scalar representation of an array, Perl believes you should have the number of elements. Most sensible thing I can imagine for it to do, really.