Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: An introduction to POE

by Coruscate (Sexton)
on Aug 10, 2003 at 09:14 UTC ( #282587=note: print w/ replies, xml ) Need Help??

in reply to An introduction to POE

hrmm... your script fails horribly for me. It freezes after I type the first character. The 'Type fast:' prompt is also right-flushed on my terminal. Uncommenting your cygwin line fixes the right-flushed text, but that is a bad way to do it. $/ is best kept at "\n". Try using \015\012 instead of \r\n as well. "\r\n" and "\015\012" are not guaranteed to be the same value. So to beat the snot out of POE for once (and most likely only time) in my life heh:

#!/usr/bin/perl -w $|++; use strict; my ($input, $failed); STARTIT: eval { local $SIG{ALRM} = sub { die "timed out\n" }; print 'You have 10 seconds. Type fast: '; alarm 10; chomp( $input = <STDIN> ); alarm 0; }; if ($@) { if ($@ eq "timed out\n") { if (++$failed == 3) { print "\nTimed out 3 times. You're toast!\n\n" and exit; } else { print "\nTimed out. Try again!\n\n"; } } else { die "Unhandled error: $@"; } } else { print "You said '$input'. 10 more seconds now!\n\n"; } goto STARTIT;

If the above content is missing any vital points or you feel that any of the information is misleading, incorrect or irrelevant, please feel free to downvote the post. At the same time, please reply to this node or /msg me to inform me as to what is wrong with the post, so that I may update the node to the best of my ability.

Comment on Re: An introduction to POE
Download Code
Re: Re: An introduction to POE
by RMGir (Prior) on Aug 10, 2003 at 12:59 UTC
    What platform did it freeze on? You may want to file a bug report.

    I'm not sure what the behaviour of \n\r will be on different platforms.

    I'm QUITE sure that using \012\015 is a bad idea. What if the poor user is running on a EBCDIC system? \n\r has a chance of doing the right thing, \012\015 doesn't.

    You solution with signals does answer the original question, but the point wasn't to solve that problem perfectly, it was to introduce POE. Besides, you didn't implement command-line history or editing :)) (j/k)

      I'm QUITE sure that using \012\015 is a bad idea ... \n\r has a chance of doing the right thing.

      Um, I don't think so - Read the perlport man page under the heading "Newlines". To quote:

      A common misconception in socket programming is that "\n" eq "\012" everywhere. When using protocols such as common Internet protocols, "\012" and "\015" are called for specifically, and the values of the logical "\n" and "\r" (carriage return) are not reliable.

      print SOCKET "Hi there, client!\r\n"; # WRONG print SOCKET "Hi there, client!\015\012"; # RIGHT

      This is equally applicable to the use of the literal \r and \n in general programming.


      perl -le 'print+unpack"N",pack"B32","00000000000000000000001001111000"'

        (We're getting pretty far off the topic of POE here...)

        You are correct for network protocols. Of course, at that level it's important that the correct bytes are sent, if you're doing raw FTP or RSH, for instance.

        But for terminal interactions, you have to have "the right thing" happen. And what does the right thing can be different from platform to platform. In those cases, I think \n and \r are the correct choices.

        Even if you're accessing another system remotely, it's the terminal driver on that system that will make the decision how to translate local \n into the right thing on the wire.

      Some versions of Linux don't seem to get along with non-blocking ReadKey. I received a test case about it in e-mail on 23 August:

      #!/usr/bin/perl use Term::ReadKey; ReadMode 5; # Turn off controls keys while (1) { while (not defined ($key = ReadKey(-1))) { print "Foo\n"; sleep (1); } print "Get key $key\n"; ($key eq 'q') and last; } ReadMode 0; # Reset tty mode before exiting

      If the test case fails for you, please e-mail a note to so (a) I'll see it, and (b) I won't forget it. :) Since it's a platform-dependent problem, it would help a lot if output from uname -a and perl -V were included. Thanks.

      -- Rocco Caputo - -

        (Also emailed as requested)

        It's not very happy on a redhat 9 box:

        perl Foo Foo Foo Foo Foo Foo Foo Foo Foo Foo Terminated ~/xml mike@tux6202 $ qqqqqqq ~/xml $ perl -v This is perl, v5.8.0 built for i386-linux-thread-multi (with 1 registered patch, see perl -V for more detail) Copyright 1987-2002, Larry Wall ... ~/xml $ uname -a Linux tuxXXXX 2.4.20-18.9smp #1 SMP Thu May 29 06:55:05 EDT 2003 i686 +i686 i386 GNU/Linux
        It DOES, however, work fine on a Redhat 7.x box with perl 5.6.1, with uname info:
        Linux tuxYYY 2.4.18-26.7.xsmp #1 SMP Mon Feb 24 09:37:16 EST 2003 i68 +6 unknown


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://282587]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-07-24 07:22 GMT
Find Nodes?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:

    Results (158 votes), past polls