Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I was also confused about what this $$blk_ref was about. And I just punted that issue in my direct post. It would be helpful if the OP showed more of his application. Dereferencing a ref to a single scalar is a relatively rare thing in Perl. That is because Perl array iterator operations are very good at hiding this nastiness.

For fun, I used your example data and coded the loop a couple of different ways. Neither of which use an explicit dereferencing operation.

use strict; use warnings; use Data::Dump qw(dd); my @strings = ( 'SMS,SMS1,20190811', 'SMS,SMSh,20190811', 'SMS,SMSH,20190811', 'SMS,SMSx,20190811', 'SMS,SMSi,20190811', 'SMS,SMSX,20190811', 'SMS,SMSI,20190811', ); # map{} is a logical thought for an array transformation # # Could assign back to @strings or can make # a new array, @strings2 # Could use an "if" and concatenate a message if true # and return $_ in any event. Ternary operator here # gives a place to put a single token that is # not "SMSblk" my @strings2 = map{/SMS[1HI]/i ? "$_ is SMSblk":$_}@strings; dd \@strings2; =prints: [ "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", ] =cut # Or with a for loop instead of map{} # to modify original array: # Foreach creates an alias and modifying that # alias modifies the original array # No tricky dereferencing is needed. foreach (@strings) { $_ .= " is SMSblk" if /SMS[1HI]/i; } dd \@strings; =prints: [ "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", ] =cut

In reply to Re^2: Case insensitive string comparison (updated x2) by Marshall
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 romping around the Monastery: (4)
As of 2024-04-19 01:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found