Re: Help on reading esc sequence

[email protected] (Paul Archer)
Newsgroups perl.beginners.cgi
Message-ID <[email protected]>
The reason this works is that when you read from STDIN, you are getting the 
newline from when the user of the program hits return. Using '=~' is 
implying a 'match', which will match the string/regexp supplied within the 
variable's value. 'eq' means the two strings have to be exactly equal to 
each other, but your variable actually has the value of '\e\n'. You should 
get into the habit of 'chomp'ing values as soon as you read them in so you 
don't have that problem.

Paul


7:34pm, Susheel Koushik wrote:

> hi amrita,
>
> use if($var1 =~ '\e') inplace of if(var1 eq '\e')
>
>
>
> On 6/11/07, Amrita Roy <[email protected]> wrote:
>> Hello,
>> 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')
>> {
>>   print "Hello \n";
>> }
>> 
>> else
>> {
>>   print "World \n";
>> }
>> 
>> 
>> --
>> Amrita Roy
>> Rebaca Technology Pvt Ltd.
>> Sector 5, Saltlake,
>> Kolkata
>> Email : [email protected]
>> 
>
> -- 
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>
>
>



-----------------------------------------------------------
If you live in a small town /You might meet a dozen or two/
Young alien types /Who step out /And dare to declare/
"We're through being cool."  --  Devo, "Through Being Cool"
-----------------------------------------------------------
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.