defyance has asked for the wisdom of the Perl Monks concerning the following question:

Well, reap this if you will, but I'm asking cause I can't seem to find a straight answer, just really good ideas.

I was trying to make <STDIN> in a small script read quite a bit of data, when I ran into a problem, it didn't read it all, instead it locked up the script, and I had to kill it.
No need to post any code as its just your basic;
print "Who's Yer Daddy?\n"; chomp($var=<STDIN>);
Statement.

So anywhoo, my question is this..
Is there a set Maximum Buffer setting for STDIN?
If so, is it something Perl determines, or is decided by the OS? I'll probably just rewrite the script to use Term::Readkey, cause I think it will work better for me. However, I was just curious about that. Ideas??

-- Yes, I am a criminal. My crime is that of defyance.

Replies are listed 'Best First'.
Re: STDIN to the Max?!?
by jepri (Parson) on Mar 21, 2002 at 05:35 UTC
    Your problem is that the diamond operator works on line at a time. Your user types the answer ( "Me!" ), then presses return, then your program proceeds.

    Perl is not set up very well to read single keys. This is a separate issue to buffering

    ____________________
    Jeremy
    I didn't believe in evil until I dated it.

Re: STDIN to the Max?!?
by shotgunefx (Parson) on Mar 21, 2002 at 08:13 UTC
    I'm not exactly why your script crashed. Was there any data in STDIN? Did you try typing something and hitting enter? It might have just been blocking for data\n The diamond operator is line oriented.
    When you say "quite a bit of data" doyou mean input that may have line newlines etc.. like a cat bigfile | perlscript.pl?

    If you want to slurp filehandled data into a scalar and not just one line at a time, you should undefine the line separator variable like so.
    { local $/ = undef; # Temporarily undefine record seperator. my $var = <STDIN>; # Read it all in. } # Block ends so local restores value.


    As far as limits, I don't know of any abitrary ones but I would think it would be determined by your C libraries that perl was compiled with.

    -Lee

    "To be civilized is to deny one's nature."
Re: STDIN to the Max?!?
by jeffenstein (Hermit) on Mar 21, 2002 at 08:47 UTC

    Do you want to do this instead?

    chomp(@var = <STDIN>);

    $var = <STDIN> will only read one line at a time.

      The scalar was a typo, this particular field required an @array just like you said, but it still only takes in 18 lines of data. That's not really an issue, I was just curious as to if there was a max amount of data STDIN can handle, in general. Its not an important script that I was writing, just something I was playing with that sparked my curiosity. Thanks for the ideas however, and ++ to you all!

      -- Yes, I am a criminal. My crime is that of defyance.
      But if it's to be a 'small' script, then using @var will occupy a lot more memory than the loop sholud...
      Everything depends on what do you mean by 'quite a bit of data' :-)

      Greetz, Tom.
        See, I'm not even worried about the script, I'll make it work, that's not a prob. I was just wondering if anyone knew of any limitations on the amount of data that STDIN can handle, I probably should have made that more clear..

        And tmiklas your right about it occupying more mem, but as you know, a @var handles multiple scalars which is what I want, in order to split the imputed data..

        -- Yes, I am a criminal. My crime is that of defyance.