Question

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");
}
Was it helpful?

Solution

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.

OTHER TIPS

Change in your code

$seq = <>;

to

chomp($seq = <>);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top