How to make this case insenstive

D

Daniel

I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

....
..

Is this possible?

Thank you!
 
T

Tony Curtis

Daniel said:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

That's easy, canonicalize both of them: e.g. lc() or uc(), q.v.

hth
t
 
S

Sisyphus

Daniel said:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

my $line = DBI::neat_list(\@row, 70, ',');
if (lc($name) ne lc($row[1]))
do
error message

Cheers,
Rob
 
I

it_says_BALLS_on_your forehead

I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

...
.

an alternative to the lc() or uc() solution is to use a regex
(although this is probably less efficient).

if ( $name =~ m/$row[1]/i ) {
do {
blah
 
J

Jürgen Exner

Daniel said:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
Is this possible?

Use normal forms, i.e. convert both to all lower or all upper case:
if (lc($name) ne lc($row[1])) {
If you loop through @row again and again it might be faster to store the
text in normal form.

Or you can use pattern matching with the /i option, but you need to be
careful to anchor the pattern at both ends and to block RE special
characters from being interpreted as such.

jue
 
I

it_says_BALLS_on_your forehead

Daniel said:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.
my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
Is this possible?

Use normal forms, i.e. convert both to all lower or all upper case:
if (lc($name) ne lc($row[1])) {
If you loop through @row again and again it might be faster to store the
text in normal form.

Or you can use pattern matching with the /i option, but you need to be
careful to anchor the pattern at both ends and to block RE special
characters from being interpreted as such.

gah! i was thinking about anchoring, but completely forgot to include
them in my post. thanks jue. i forgot about the escapes too, so double
thanks.
 
D

Dr.Ruud

it_says_BALLS_on_your forehead schreef:
Daniel:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

an alternative to the lc() or uc() solution is to use a regex
(although this is probably less efficient).

if ( $name =~ m/$row[1]/i ) {
do {
blah

Missing: quotemeta.
 
J

Josef Moellers

it_says_BALLS_on_your forehead said:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

...
.


an alternative to the lc() or uc() solution is to use a regex
(although this is probably less efficient).

if ( $name =~ m/$row[1]/i ) {
do {
blah

$name = "ThisIsALongFilename";
would match
$row[1] = "Filename";

You should anchor your pattern:

$name =~ m/^$row[1]$/i;
 
U

Uri Guttman

R> it_says_BALLS_on_your forehead schreef:
Daniel:
I am checking to see if the name is the same name as in $row[1] but
should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

an alternative to the lc() or uc() solution is to use a regex
(although this is probably less efficient).

if ( $name =~ m/$row[1]/i ) {
do {
blah

R> Missing: quotemeta.

also missing regex anchors which are needed since he did 'ne'.

uri
 
D

Dr.Ruud

Uri Guttman schreef:
Ruud:
it_says_BALLS_on_your forehead:
Daniel:
I am checking to see if the name is the same name as in $row[1]
but should be case insensitive.

my $line = DBI::neat_list(\@row, 70, ',');
if ($name ne $row[1])
do
error message

an alternative to the lc() or uc() solution is to use a regex
(although this is probably less efficient).

if ( $name =~ m/$row[1]/i ) {
do {
blah

Missing: quotemeta.

also missing regex anchors which are needed since he did 'ne'.

ACK.

He did mention "the name in $var" though, which can be read as that $var
can contain more than just the name.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,276
Latest member
Sawatmakal

Latest Threads

Top