Re: Help on reading esc sequence

[email protected] (Paul Lalli)
Newsgroups perl.beginners.cgi
Organization http://groups.google.com
Message-ID <[email protected]>
On Jun 11, 9:23 am, [email protected] (Amrita Roy) wrote:
> Actually i m running a process using perl script.so i want to do that if i
> press ESC from the keyboard it will come out of the loop n comes out of the
> function.I am trying to read the esc character using "\e"but it is not
> responding.I have even tried with hex (1B) value of esc charcter but still
> it was not respoding .
> Here is code snippet:
>
> #!/C:/Perl/bin -w
>  my $var1;
>
> $var1 = <STDIN>;
> if($var1 eq '\e')

You have two problems here.

1) single quotes do not interpolate.  The do not interpolate
variables, and they do not interpolate character escapes.
2) When you read from Standard Input, the trailing newline is
included. You need to chomp.  perldoc -f chomp

my $var1 = <STDIN>;
chomp $var1;
if ($var eq "\e") { ... }

Paul Lalli
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.