IO::Null(3)
β¨ IO::Null π
okay bestie, this is IO::Null β a class for null filehandles, straight out of the User Contributed Perl Documentation. it's short, it's silly, and it slays. π
πΈ SYNOPSIS πΈ
use IO::Null;
my $fh = IO::Null->new;
print $fh "I have nothing to say\n"; # does nothing.
# or:
$fh->print("And I'm saying it.\n"); # ditto.
# or:
my $old = select($fh);
print "and that is poetry / as I needed it --John Cage"; # nada!
select($old);
Or even:
tie(*FOO, IO::Null);
print FOO "Lalalalala!\n"; # does nothing.
π« DESCRIPTION π«
okay so this is a class for null filehandles. that's the whole vibe. π¦
calling a constructor of this class always succeeds, and hands you back a fresh new null filehandle. no drama, no failure, it just works.
writing to any object of this class is always a no-operation, and it returns true. you're basically screaming into the void and the void is like "yeah sure π ".
reading from any object of this class is always no-operation too, and it returns empty-string or empty-list, as appropriate. depends on what you asked for, bestie.
π WHY π
you could say:
open(NULL, '>/dev/null') || die "WHAAT?! $!";
and get a null FH that way. sure. but not everyone is using an OS that has a /dev/null. π so like... not the move for everybody.
π IMPLEMENTATION π
this is a subclass of IO::Handle. applicable methods get subs that do nothing, and return an appropriate value. that's it. that's the whole thing. iconic minimalism, fr fr.
π§ SEE ALSO π§
IO::Handle, perltie, IO::Scalar
π CAVEATS π
okay this is the part where things get weird and i need you to stay with me.
- This:
use IO::Null;
$^W = 1; # turn on warnings
tie(*FOO, IO::Null);
print FOO "Lalalalala!\n"; # does nothing.
untie(*FOO);
has been known to produce this odd warning:
untie attempted while 3 inner references still exist.
and the author has no idea why. literally no idea. π
- Furthermore, this:
use IO::Null;
$^W = 1;
*FOO = IO::Null->new;
print FOO "Lalalalala!\n"; # does nothing.
close(FOO);
emits these warnings:
Filehandle main::FOO never opened.
Close on unopened file <GLOB>.
...which are, in fact, true. the FH behind the FOO{IO} was never opened on any real filehandle. and the author would welcome anyone's (working) suggestions on how to suppress these warnings. π«Ά
you get the same warnings with:
use IO::Null;
$^W = 1;
my $fh = IO::Null->new;
print $fh "Lalalalala!\n"; # does nothing.
close $fh;
Note that this, however:
use IO::Null;
$^W = 1;
my $fh = IO::Null->new;
$fh->print("Lalalalala!\n"); # does nothing.
$fh->close();
emits no warnings. β¨ slay.
- the author doesn't know if you can successfully untaint a null filehandle. unknown. mystery. leaving it there. π
- This:
$null_fh->fileno
will return a defined and nonzero number, but one you're not likely to want to use for anything. see the source.
- These docs are longer than the source itself. read the source! no cap.
π COPYRIGHT π
Copyright (c) 2000 Sean M. Burke. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π AUTHOR π
Sean M. Burke "sburke@cpan.org"
and that's the whole page, bestie!! this was pulled from perl v5.42.0, dated 2025-07-25, and it's the IO::Null(3) manual page. go write to a void and feel zero consequences. π¦β¨π
π¦ where this page comes from
- fedora 43: perl-IO-Null 1.01-49.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms