Sample Header Ad - 728x90

why perl's if condition is satisfying empty string?

0 votes
1 answer
745 views
The below code works fine, except for the part the STDIN takes an empty value also and goes to first selection "print "Selected Y \n";". If I use && $check ne "" ) { after /^[Y]?$/i, the issue with empty STDIN also solves. But the question is why empty value passes there? my $check = 'NULL'; while ( $check eq 'NULL' ) { print "Do you wish to continue? (Y/N)\n\n"; print "Enter Selection: "; chomp ( $check = ); if ( $check =~ /^[Y]?$/i ) { print "Selected Y \n"; } elsif ( $check =~ /^[N]$/i ) { print "Selected N \n"; } else { print "\nInvalid input, please re-enter selection. (Y/N) \n\n"; $check = 'NULL'; } I am new to perl, can someone help me understand the behavior?
Asked by prado (960 rep)
Nov 18, 2020, 07:16 AM
Last activity: Nov 18, 2020, 09:16 AM