Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:  <%-{-{-{-<


In reply to Re: Case insensitive string comparison (updated x2) by AnomalousMonk
in thread Case insensitive string comparison by DAN0207

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-24 06:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found