in reply to compare individual string with complete array

Hello rohan_532,

First of all welcome to the monastery.

I was reading through your question and it is not so clear to me, maybe another monk can understand but what you are trying to achieve?

Since you are already comparing your array with the string:

if (grep { /(?i)\Q$db_description\E/ } @steps_name)

What is that you want to get. Can you provide us a pseudo code of the input lines and the expected output. Provide us a sample of input data so we can replicate your problem. In general please update your question based on How do I post a question effectively?. Do not take this the wrong way help us more to help you.

Update: rohan_532 Do Not Re Post Your Questions on top of other questions that you have posted Re^2: regex for case insensitive. This will produce chaos on your questions and answers and also people that might refer to these questions on future.

Looking forward to your update.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^2: compare individual string with complete array
by rohan_532 (Initiate) on May 31, 2017 at 10:44 UTC

    hello in my program the $db_description is a variable which contains values such as $db_description="MOVE 1-2 STEPS" i want to check if this $db_description is present or matches in the above mentioned @steps_name array. the code i use only matches exact string ,I need any case insensitive even if 1-2 is present in string it should match with array

      Hello again rohan_532,

      You are mixing many questions and issues here.

      Having a case sensitive string is something different that comparing with a regex with numbers. So take a step backwards and analyze it.

      If you have an upper case string and you want to convert it to a lower case you can simply use lc or the opposite assume that you have a lower case string and you want to convert to upper case uc. Or even igf you manage to split the string into pieces and you want to make only the first letter of the string upper case ucfirst.

      Regarding the regex part of your question:

      #!usr/bin/perl use strict; use warnings; my @steps_name = ("1-2 Steps", "5-7 Steps", "8-10 Steps", "11-15 Steps +"); foreach my $element (@steps_name) { print "Matched with ".$element."\n" if ($element =~ /[0-9]-[0- +9]/); } __END__ $ perl test.pl Matched with 1-2 Steps Matched with 5-7 Steps Matched with 8-10 Steps Matched with 11-15 Steps

      As you can see this will match with all elements, so you need to be a bit more specific on what you want to compare against. For example 1-2 Steps only, or multiple choices?

      Again I am looking forward to update your question with more details.

      Update: Have you read the answers that marinersk and AnomalousMonk have already provided you on your previous question regex for case insensitive? I looks like they have already addressed your problem.

      Hope this is more clear now, programming gives you infinite possibilities, you have to tell us exactly what is the desired output.

      Seeking for Perl wisdom...on the process of learning...not there...yet!
        apologies for the re posting and incorrect process,I have read the answer but the scenario is different i have on fixed array with standard data and repeating variable ($db_description) to compare with the array. The comparing will be done for multiple choice . Example:- The description variable value is the one to compare in array.