[TxMt] Re: Interactive input in Textmate (for Perl)

Jon2010 octoberlyz at hotmail.com
Mon Mar 8 21:14:10 UTC 2010


Alex:

Thanks very much for the explanation! I appreciated it!

Jon


Alex Ross-11 wrote:
> 
> On Mar 7, 2010, at 7:27 PM, Jon2010 wrote:
> 
>> When I was trying to do some interactive input with Perl in TM, I got
>> some
>> weird output.
>> 
>> For example, I use this script:
>> 
>> #!/usr/bin/perl -w 
>> $pi = 3.14; 
>> print "What is the radius? "; 
>> chomp($radius = <STDIN>); 
>> $circ = 2 * $pi * $radius; 
>> print "The circumference of a circle of radius $radius is $circ.\n"; 
>> 
>> When I run the script and input "4", the output is this:
>> 
>> 4
>> What is the radius? The circumference of a circle of radius 4 is 25.12.
>> 
>> I mean, when I input "4", I don't see the msg "What is the radius?".
>> Shouldn't TM first show this msg and then, as the user, I input "4"?
>> 
>> Any ideas about this?
> 
> This is the expected behavior. :)
> 
> When you print “What is the radius?”  The output buffer isn't flushed,
> because that string doesn't end with a newline.  Then, your script reads
> on stdin and the dialog pops up.  The “4” is printed (in italics), because
> interactive input echos your typing.
> 
> The behavior is slightly different in Terminal because there perl knows it
> is connected to a TTY, so it doesn't buffer it's output.
> 
> You can disable buffering by placing this simple line of code at the start
> of your script:
> 
>> if ($ENV{'TM_PID'}) { $| = 1 };
> 
> This produces the behavior you are expecting.
> 
> —Alex
> 
> _______________________________________________
> textmate mailing list
> textmate at lists.macromates.com
> http://lists.macromates.com/listinfo/textmate
> 
> 

-- 
View this message in context: http://old.nabble.com/Interactive-input-in-Textmate-%28for-Perl%29-tp27816791p27827662.html
Sent from the textmate users mailing list archive at Nabble.com.




More information about the textmate mailing list