if ( $key eq "\e" && $key eq "\x1b" && $key eq "\033" && $key eq "\c[" && $key eq "\x{1b}" && $key eq "\o{33}" && $key eq "\N{ESCAPE}" && $key eq "\N{U+001B}" && $key eq v27 && ord($key) == 27 && ord($key) == 0x1b && ord($key) == 033 && ord($key) == 0o33 && ord($key) == 0b11011 ) { print "Escape pressed\n"; }

I wonder how much of it remains after parsing and optimizing:

#!perl use strict; use warnings; use charnames qw( :full ); for my $key ("r", "x", "\e", "z") { if ( $key eq "\e" && $key eq "\x1b" && $key eq "\033" && $key eq "\c[" && $key eq "\x{1b}" && $key eq "\o{33}" && $key eq "\N{ESCAPE}" && $key eq "\N{U+001B}" && $key eq v27 && ord($key) == 27 && ord($key) == 0x1b && ord($key) == 033 # that's not perl: && ord($key) == 0o33 && ord($key) == 0b11011 ) { print "Escape pressed\n"; } }
X:\>perl -MO=Deparse 11144112.pl use charnames (':full'); use warnings; use strict 'refs'; BEGIN { $^H{'charnames_inverse_ords'} = q(HASH(0x2a62c30)); $^H{'charnames_stringified_inverse_ords'} = q(); $^H{'charnames'} = q(CODE(0x2b77d90)); $^H{'charnames_full'} = q(1); $^H{'charnames_scripts'} = q(); $^H{'charnames_name_aliases'} = q(HASH(0x2a62c18)); $^H{'charnames_ord_aliases'} = q(HASH(0x2a62c90)); $^H{'charnames_short'} = q(0); $^H{'charnames_stringified_names'} = q(); $^H{'charnames_stringified_ords'} = q(); } foreach my $key ('r', 'x', "\e", 'z') { if ($key eq "\e" and $key eq "\e" and $key eq "\e" and $key eq "\e +" and $key eq "\e" and $key eq "\e" and $key eq "\e" and $key eq "\e" + and $key eq v27 and ord $key == 27 and ord $key == 27 and ord $key = += 27 and ord $key == 27) { print "Escape pressed\n"; } } 11144112.pl syntax OK X:\>perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x +64-multi-thread Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge. X:\>

So, clearly all variants of writing "\e" and 27 were unified, but I kind of expected that the optimizer would eliminate repeated identical expressions. Like this:

if ($key eq "\e" and $key eq v27 and ord $key == 27) { print "Escape pressed\n"; }

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

In reply to Re^6: Capture a non-printable char and test what it is by afoken
in thread Capture a non-printable char and test what it is by almsdealer

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.