in reply to Case insensitive string comparison
First I would not match against the whole comma separated line, I would narrow the focus to the field that you are interested in. Below I use a split to get field[1]. Another poster suggested using a boundary condition in the regex for the same intended purpose (making sure you are matching against what you think that you are). We don't know what those other names or id's in the line look like, perhaps one server is "sms1Master" or whatever.
Instead of multiple "or" terms, I would use a character set in this case. This makes it easier for me to see what is going to match or not match. Of course mileage varies.
use strict; use warnings; while (<DATA>) { my $SMSfield = (split(',',$_))[1]; if ($SMSfield =~ /SMS[1HI]/i) { print "Match $SMSfield\n"; } else { print "No Match $SMSfield\n"; } } =prints Match SMS1 Match SMSh Match SMSH Match SMSi Match SMSI Match SmsI **Note this match** I think in your case, this is fine. No Match SMSx =cut __DATA__ SMS,SMS1,20190811,084500,servname,servid,servname1,s1,400,300,300,300, +300,300 SMS,SMSh,20190811,084500,servname,servid,servname1,s1,700,300,300,300, +300,300 SMS,SMSH,20190811,084500,servname,servid,servname1,s1,600,300,300,300, +300,300 SMS,SMSi,20190811,084500,servname,servid,servname1,s1,800,300,300,300, +300,300 SMS,SMSI,20190811,084500,servname,servid,servname1,s1,500,300,300,300, +300,300 SMS,SmsI,20190811,084500,servname,servid,servname1,s1,500,300,300,300, +300,300 SMS,SMSx,20190811,084500,servname,servid,servname1,s1,500,300,300,300, +300,300
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Case insensitive string comparison
by AnomalousMonk (Archbishop) on Jun 28, 2020 at 05:21 UTC | |
by Marshall (Canon) on Jun 29, 2020 at 06:59 UTC | |
by DAN0207 (Acolyte) on Jun 30, 2020 at 12:09 UTC | |
by AnomalousMonk (Archbishop) on Jun 30, 2020 at 17:25 UTC | |
by DAN0207 (Acolyte) on Jul 01, 2020 at 06:16 UTC |