문제

I'm trying to write a loop that will determine whether the user input matches the string $rev. No matter what I type in for $seq, it returns that it is NOT a match, even if it actually is. What am I doing wrong? Thanks for any help.

$seq = <>;
$rev = "string";
if ($seq eq $rev){
    printf("The two strings match.\n");
}
else {
    printf("The two strings do NOT match.\n");
}
도움이 되었습니까?

해결책

You need to chomp your input to remove the newline character:

$seq = <>;
chomp $seq;
$rev = "string";
if ($seq eq $rev){
    print "The two strings match.\n";
}
else {
    print "The two strings do NOT match.\n";
}

Also, use print instead of printf since you are not specifying a format.

다른 팁

Change in your code

$seq = <>;

to

chomp($seq = <>);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top