Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Diff w/ or w/o ' ' 3

Status
Not open for further replies.

JohnLucania

Programmer
Oct 10, 2005
96
US
use Test::Simple tests

print "Enter sequences: ";
chomp(@CheckChar= <STDIN>);

// when ‘abd’ (please note ‘ ‘) is entered, it gives me.
ok( grep(/abd|ABD/i, @CheckChar), "A word, 'abd', checks" );

ok 1 - A word, 'abd', checks

// when abd (please note w/o ‘ ‘) is entered, it gives me ‘Failed test’
 
What I have is:

#! /usr/bin/perl
use strict;
use warnings;
use diagnostics;

use Test::Simple tests => 3;

use vars qw(@CheckChar);
use TChar;

BEGIN {
print "Enter sequences and 'enter' and then Ctrl + D: ";
chomp(@CheckChar= <STDIN>);
}

bla ....


sub StartChar {
return(1) if grep(/abd|ABD/i, @CheckChar);
return(0);
}

bla ....

ok( grep(/abd|ABD/i, @CheckChar), "A word, 'abd', checks" );

jl
 
John,

why are you using Test:Simple? I'm convinced that you are on a wild goose chase (unless you're developing a CPAN module) and much simpler language constructs will suffice.

f

[&quot;]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.[&quot;]
--Maur
 
/abd|ABD/i

you use the i operator in your regexp telling the regexp to ignore case but you include upper and lower case in your regexp. Makes no sense to do that. It should be:

/abd/i

or:

/ABD/i

they are both the same since the regexp is ignoring case.

 
It is interesting to note that /i can be very expensive.
It is usually wiser (where sensible and possible) to use
/abd|ABD/
as opposed to
/abd/i
Also you can control case a little more accurately like this:
/[Cc]apital/
to allow for a word that may be capitalised but must be generally in lower case.
Just a little food for thought.


Trojan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top