in reply to Re^2: compare individual string with complete array
in thread compare individual string with complete 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!

Replies are listed 'Best First'.
Re^4: compare individual string with complete array
by rohan_532 (Initiate) on May 31, 2017 at 11:38 UTC
    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.

      Hello rohan_532,

      I am sorry but I am not able to understand what you mean.

      I will try guess your way of thinking and you can verify or falsify or correct me if this is what you are looking for.

      Based on your answer Example:- The description variable value is the one to compare in array., let's create a scenario with sample data something that YOU should have done so we will be able to replicate the problem.

      #!usr/bin/perl use strict; use warnings; # Variables that I will extract from the escel sheet my @steps_name = ("1-2 Steps", "5-7 Steps", "8-10 Steps", "11-15 Steps +"); #regex that I want to match against foreach (@steps_name) { print "Matched with ".$_."\n" if /(?:\b8-10 Steps\b|\b11-15 St +eps\b)/; } __END__ $ perl test.pl Matched with 8-10 Steps Matched with 11-15 Steps

      You can combine regular expression if, if this is what you are looking for. Provide us a sample of expected input and desired matched output. It does not have to be compiling code, produce a pseudo code.

      Update: Apologies if I sounded a bit harsh but we need to know what exactly you are looking for, so we can help you as soon as possible. If your question is still not answered please provide us more information.

      Hope this helps.

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

        Thank you for the time and help receiving , I am providing a sample pseudo code to get clear idea the $description$i is to be compared every time with the @steps_name array

        my @db_description=("MOVE 3-4 STEPS TO GB FIXTURE","WITHIN REACH TO CH +ECK","GET BEAM","PUSH/PULL ( >= 30 CM)","BEAM 2-3 TIMES","MOVE 8-10 S +TEPS TO HOIST"); my @steps_name = ("1-2 Steps", "5-7 Steps", "8-10 Steps", "11-15 Steps +"); for(my $i=0;$i<@db_description;$i++) { if (grep { /(?i)\Q$db_description[$i]\E/ } @steps_name) + { print "<br><h1>Element '$db_description[$i]' foun +d " ; } else { print "<br>$db_description[$i] not found </br>" } }

        thank you for the patience

        update - i want description array to iterate and check in @steps_name array every time for that i am using grep { /(?i)\Q$db_description$i\E/ } @steps_name.