perl_seeker has asked for the wisdom of the Perl Monks concerning the following question:
When we run the above code with $stri equal to "abctest" we should get a match in the second section of loops onlymy $stri="abctest"; my @one=('a','b','c','d','e','f','g'); my $part; my $lone=@one; my $first_char=substr($stri,0,1); #print "\n$first_char"; my $second_char=substr($stri,1,1); #print "\n$second_char"; my $third_char=substr($stri,2,1); #print "\n$third_char"; if ($first_char eq 'a' || $first_char eq 'b'){ for(my $ne=0;$ne<$lone;$ne++){ if ($second_char eq $one[$ne]) { if ($third_char ne 'c' || $third_char ne 'd'){ $part=substr($stri,0,2); print "\nThe string in part:"; print"\n$part"; } } } } if ($first_char eq 'a' || $first_char eq 'b'){ for(my $ne=0;$ne<$lone;$ne++){ if ($second_char eq $one[$ne]){ if ($third_char eq 'c' || $third_char eq 'd'){ $part=substr($stri,0,3); print "\nThe string in part:"; print"\n$part"; } } } }
This comparison does not seem to be working:The string in part: ab The string in part: abc
What is the mistake here?if ($third_char ne 'c' || $third_char ne 'd'){ $part=substr($stri,0,2);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loops and comparisons
by gjb (Vicar) on Oct 15, 2003 at 12:28 UTC | |
by perl_seeker (Scribe) on Oct 16, 2003 at 06:31 UTC | |
|
Re: Loops and comparisons
by snax (Hermit) on Oct 15, 2003 at 13:28 UTC |