Your code seems ok to me:
c:\@Work\Perl\monks>perl -wMstrict -le
"my @strings = (
'SMS,SMS1,20190811',
'SMS,SMSh,20190811',
'SMS,SMSH,20190811',
'SMS,SMSx,20190811',
'SMS,SMSi,20190811',
'SMS,SMSX,20190811',
'SMS,SMSI,20190811',
);
;;
for my $s (@strings) {
my $ref_s = \$s;
print qq{'$$ref_s' matches}
if $$ref_s =~ /SMSi/i
|| $$ref_s =~ /SMSI/i
|| $$ref_s =~ /SMSh/i
|| $$ref_s =~ /SMSH/i
|| $$ref_s =~ /SMS1/
;
}
"
'SMS,SMS1,20190811' matches
'SMS,SMSh,20190811' matches
'SMS,SMSH,20190811' matches
'SMS,SMSi,20190811' matches
'SMS,SMSI,20190811' matches
What am I doing differently from what you're doing?
Update 1: Here's a variation showing assignment via reference (and aliasing). Again, I think it works the way I think you think it should work. (Maybe take a look at Short, Self-Contained, Correct Example.)
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my @strings = (
'SMS,SMS1,20190811',
'SMS,SMSh,20190811',
'SMS,SMSH,20190811',
'SMS,SMSx,20190811',
'SMS,SMSi,20190811',
'SMS,SMSX,20190811',
'SMS,SMSI,20190811',
);
;;
for my $s (@strings) {
my $ref_s = \$s;
$$ref_s = 'SMSblk'
if $$ref_s =~ /SMSi/i
|| $$ref_s =~ /SMSI/i
|| $$ref_s =~ /SMSh/i
|| $$ref_s =~ /SMSH/i
|| $$ref_s =~ /SMS1/
;
}
;;
dd \@strings;
"
[
"SMSblk",
"SMSblk",
"SMSblk",
"SMS,SMSx,20190811",
"SMSblk",
"SMS,SMSX,20190811",
"SMSblk",
]
Update 2: BTW: I'd tend to write something like this a bit differently:
c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le
"my @strings = (
'SMS,SMS1,20190811',
'SMS,SMSh,20190811',
'SMS,SMSH,20190811',
'SMS,SMSx,20190811',
'SMS,SMSi,20190811',
'SMS,SMSX,20190811',
'SMS,SMSI,20190811',
);
;;
for my $s (@strings) {
my $ref_s = \$s;
$$ref_s .= ' is SMSblk' if $$ref_s =~ /SMS[iIhH1]/;
}
;;
dd \@strings;
"
[
"SMS,SMS1,20190811 is SMSblk",
"SMS,SMSh,20190811 is SMSblk",
"SMS,SMSH,20190811 is SMSblk",
"SMS,SMSx,20190811",
"SMS,SMSi,20190811 is SMSblk",
"SMS,SMSX,20190811",
"SMS,SMSI,20190811 is SMSblk",
]
And maybe also throw in some kind of boundary assertion like
\b so the final regex might look like
/ \b SMS[iIhH1] \b /x
to prevent a string like
'SMS,xSMSHx,20190811' from matching.
Give a man a fish: <%-{-{-{-<
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.