enter key or carriage return as input in perl

hi experts

Question in perl
i'm creating a script to take from user a different inputs one of them is the carriage return .. so that i want to make an if condition if the user hit enter key the user will go to previous step

it something like that

chomp ($input = <STDIN>);
if ($input =~ /\n/)
{
goto previous;
}

i tried /r /n and both with no hope !

what the pattern i must match to detect the enter key from the user ?

thanks
Ahmed Douban

Remove the chomp part.
$input = <STDIN>;
then if ($input =~ /\n/) should work.

1 Like
 
if ($input =~ /\015\012/)
 

On most operating systems, lines in files are terminated by one or two characters that signal the end of the line. The characters vary from system to system. Unix traditionally uses \012 (that is, the octal 12 character in ASCII), one type of DOSish I/O uses \015\012, and Macs uses \015. Perl uses \n to represent a "logical" newline, regardless of platform. In MacPerl, \n always means \015. In DOSish Perls, \n usually means \012, but when accessing a file in "text mode", it is translated to (or from) \015\012, depending on whether you're reading or writing. Unix does the same thing on terminals in canonical mode. \015\012 is commonly referred to as CRLF.

http://docstore.mik.ua/orelly/perl/prog3/ch25_01.htm

1 Like

ya it works !
thanks mate
:wall::wall::wall::wall::wall::wall::wall::wall::wall: