I'm in need of a Perl plumber. Got a problem running Lincoln Stein's sample code on page 48 in both Linux and Windows. Neither system delivers the results promised in the book.

Windows98 (Perl 5.6.1) outputs this: Bad command or file name Writing line 1 Writing line 2 Writing line 3 Writing line 4 Writing line 5 Writing line 6 Writing line 7 Writing line 8 Writing line 9 Writing line 10 Wrote 1 lines of text While Linux (Perl 5.005) gives me this: Writing line 1 Broken pipe Stein says the script will do this: Writing line 1 Read_three got: This is line number 1 Writing line 2 Read_three got: This is line number 2 Writing line 3 Read_three got: This is line number 3 Writing line 4 Broken pipe
For the code from the book, see next page:
# First file ================================== #!/usr/bin/perl # file: write_ten.pl # Figure 2.3: Write ten lines of text to a pipe use strict; open (PIPE,"| read_three.pl") or die "Can't open pipe: $!"; select PIPE; $|=1; select STDOUT; my $count = 0; for (1..10) { warn "Writing line $_\n"; print PIPE "This is line number $_\n" and $count++; sleep 1; } close PIPE or die "Can't close pipe: $!"; print "Wrote $count lines of text\n"; # SECOND FILE =============================== #!/usr/bin/perl # file: read_three.pl # Figure 2.4: Read three lines of text from standard input use strict; for (1..3) { last unless defined (my $line = <>); warn "Read_three got: $line"; }

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop";
$nysus = $PM . $MCF;
Click here if you love Perl Monks


In reply to Pipe problem by nysus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.