IO::Pipe(3pm)

πŸ’– IO::Pipe(3pm) πŸ’–

okay so this is a page from the Perl Programmers Reference Guide, and bestie, it's literally all about pipes. stay with me, it's shorter than it looks and honestly kind of iconic 🫢


✨ NAME ✨

IO::Pipe β€” it supplies object methods for pipes. that's the whole vibe. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

okay so here's the first way you might use it β€” fork yourself a kid and split the pipe between you:

        use IO::Pipe;

        $pipe = IO::Pipe->new();

        if($pid = fork()) { # Parent
            $pipe->reader();

            while(<$pipe>) {
                ...
            }

        }
        elsif(defined $pid) { # Child
            $pipe->writer();

            print $pipe ...
        }

or, alternative route, just hand it a command and let it do the fork for you:

        $pipe = IO::Pipe->new();

        $pipe->reader(qw(ls -l));

        while(<$pipe>) {
            ...
        }

both are valid, both slay, pick whichever fits your situation 🌸


πŸ¦‹ DESCRIPTION πŸ¦‹

IO::Pipe gives you an interface for creating pipes between processes. that's it, that's the whole description, short and sweet, no notes πŸ’œ


🌈 CONSTRUCTOR 🌈

new ( [READER, WRITER] )

so this creates an IO::Pipe, which β€” plot twist β€” is a reference to a newly created symbol (check the Symbol package if you're curious, iykyk).

IO::Pipe::new optionally takes two arguments, and those lil guys should be objects blessed into IO::Handle, or a subclass of it. these two objects are what get used for the system call to pipe. ✨

if you give it no arguments at all? then method handles gets called on the new IO::Pipe object instead. no pressure.

these two handles just chill in the array part of the GLOB until you call either reader or writer. they're waiting. patiently. πŸ‘‘


πŸ’… METHODS πŸ’…

  • reader ([ARGS]) β€” the object gets re-blessed into a sub-class of IO::Handle and becomes the handle at the reading end of the pipe. and if you pass ARGS? then fork is called and ARGS get passed to exec. go off 🐚
  • writer ([ARGS]) β€” same situation, except this one becomes the handle at the writing end of the pipe. it also gets re-blessed into a sub-class of IO::Handle. and yep, if ARGS are given then fork is called and ARGS are passed to exec. twin behavior, different end 🫢
  • handles () β€” this method gets called during construction by IO::Pipe::new on the newly created IO::Pipe object. it returns an array of two objects blessed into IO::Pipe::End, or a subclass thereof. two lil ends, one for each side πŸ’–

πŸ”₯ SEE ALSO πŸ”₯

IO::Handle β€” go read that one next, bestie πŸ’€


πŸ‘‘ AUTHOR πŸ‘‘

Graham Barr. currently maintained by the Perl Porters. please report all bugs at <https://github.com/Perl/perl5/issues> β€” they genuinely want to hear from you, no cap πŸ™ˆ


Copyright (c) 1996-8 Graham Barr <gbarr@pobox.com>. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. πŸŽ€


okay that's the whole page, you ate it up honestly. this was perl v5.42.3, dated 2026-11-03 β€” go forth and pipe responsibly πŸ§šπŸ’œ

πŸ“¦ where this page comes from