<?xml version="1.0" encoding="windows-1252"?>
<node id="454223" title="Testing failures: How to override print to make it fail?" created="2005-05-04 23:00:17" updated="2005-08-12 23:56:13">
<type id="115">
perlquestion</type>
<author id="176576">
eyepopslikeamosquito</author>
<data>
<field name="doctext">
&lt;P&gt;
I want to test &lt;CODE&gt;open&lt;/CODE&gt; and &lt;CODE&gt;print&lt;/CODE&gt; failures.
This crude trick overrides open with a failing one:
&lt;CODE&gt;
BEGIN {
    *CORE::GLOBAL::open = sub (*;$$) { return undef };
}
open(my $fh, '&gt;', 'f.tmp') or die "error: open";
print $fh "hello\n" or die "error: print";
&lt;/CODE&gt;
However, this attempt does not override print with a failing one:
&lt;CODE&gt;
BEGIN {
    *CORE::GLOBAL::print = sub (*;@) { return undef };
}
open(my $fh, '&gt;', 'f.tmp') or die "error: open";
print $fh "hello\n" or die "error: print";
&lt;/CODE&gt;
I suspect I just need to get the right prototype for print.
How do I override the print function to make it fail?
&lt;/P&gt;
</field>
</data>
</node>
