in reply to Many-to-One pipe

(Edit: See particle's comment; all that's missing is an '*' on the locals... Removed my questions wondering why it didn't work.)

Here's a version that works for me. I reduced the limits so it didn't spam quite as much :)

#!/usr/bin/perl use warnings; use strict; my ( $ppid, $in, $out) = $$; pipe ( $in, $out) or die $!; # "Daemon" { #local STDIN = $in; local $| = 1; my $child; defined( $child = fork) or die $!; last if $child; close $out or die $!; while (<$in>){ print "Parent got: $_"; } exit 0; } # Spawn some client processess { #local STDOUT = $out; select($out); local $| = 1; for my $kid (1..10) { my $child; defined( $child = fork) or die $!; next if $child; close $in; select( undef, undef, undef, .001) while kill $ppid, 0; select( undef, undef, undef, rand(1000)/1000), print 'Child ', $kid, ' pid=', $$, ' message=', 0 | rand 10000, $/ for 1..20; exit 0; } }

--
Mike
(Edit: Added 5.6.1-friendly version of code)

Replies are listed 'Best First'.
Re^2: Many-to-One pipe
by particle (Vicar) on Aug 07, 2002 at 12:50 UTC
    Hmmm, 5.6.1 doesn't like local STDIN = $in; or local STDOUT = $out;.

    that's because it's missing the sigil... local *STDIN = $in; or local *STDOUT = $out;

    Is that a 5.8 feature? I've never seen that construct before. It'd be nice to have, though!

    this is a standard feature (assuming the syntax is correct.) the first one will fail under 5.008 with the same errors. my correction should work fine under any recent perl.

    ~Particle *accelerates*