Menu

Trouble with <STDIN>

Help
2006-10-26
2013-05-20
  • Robert Martin

    Robert Martin - 2006-10-26

    I'm have a very pecular problem when using <STDIN>...

    I'm running Eclipse 3.2 & E.P.I.C. 0.5.12, on XP

    here's the code ....

    #! /usr/bin/perl

    print "Enter the string and the number (separate lines):\n";
    $strings = <STDIN>;
    chomp($repeat = <STDIN>);
    print "Here's your output:\n";
    print $strings x $repeat;

    when I run this code through the console in Eclipse the prgram blocks for the first <STDIN> without printing the first line of text.

    I get the following in the console.....

    Robert
    4
    Enter the string and the number (separate lines):
    Here's your output:
    Robert
    Robert
    Robert
    Robert

    When I run this on through cmd.exe it runs normally, i.e. it prints a prompt to the user first, then blocks.  Also runs fine on a Solaris terminal.

    Please let me know what I can do...

    thanks,

    blkdog -

     
    • Peter Guzis

      Peter Guzis - 2006-10-26

      Just a thought, but have you tried turning on autoflush at the beginning of your script?

      $| = 1;

       
    • Robert Martin

      Robert Martin - 2006-10-26

      That worked, Thank-you, ... is this always necessary?

       
      • Jan Ploski

        Jan Ploski - 2006-10-26

        This is a FAQ. Read man perlvar for an explanation on why and when $| = 1 is necessary.

        Because so many people run into it, I am going to fix it in some near future. That is, I am going to make Perl invoked by EPIC behave as if it was writing to a real terminal if the Console option is enabled in the launch configuration.

         

Log in to post a comment.

MongoDB Logo MongoDB