Avatar of mikeysmailbox1
mikeysmailbox1
 asked on

Grepping on special characters

Hi

I have a array that has a value with special characters in it and I need to match them.

Example:    @INCOND1 = $EGH0001_#SSSR0002_OK^ODAT^AAA^$EGH0001
                                             $EGH0001_?SSSR0003_OK^ODAT^AAA^$EGH0001

The entries are with in an array and I am grepping on a an array where I am matching the value from one array to another array.

$OUTDOCOND = "$EGH0001_#SSSR0002_OK";    Or could be $OUTDOCOND = "$EGH0001_?SSSR0003_OK";

my @answerO = grep /^\Q$OUTDOCOND\E\^/, @INCOND1;

Sometimes the data is not matching even if its in the array.
Tried the \Q and \E but not sure if this is working completely.

The 3 special characters in the array are $ # ?

Not sure if there is another way to \? or \# or \$ the beginning values.

Thanks

Mike
Perl

Avatar of undefined
Last Comment
ozo

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
ozo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
ozo

perldoc perlop
...
Quote and Quote-like Operators
While we usually think of quotes as literal values, in Perl they function as operators, providing various kinds of interpolating and pattern matching capabilities. Perl provides customary quote characters for these behaviors, but also provides a way for you to choose your quote character for any of them. In the following table, a {} represents any pair of delimiters you choose.
    Customary  Generic        Meaning           Interpolates
      ''       q{}            Literal              no
      ""      qq{}            Literal              yes
      ``      qx{}            Command              yes*
            qw{}           Word list              no
      //       m{}         Pattern match        yes*
            qr{}            Pattern              yes*
             s{}{}          Substitution        yes*
            tr{}{}        Transliteration        no (but see below)
             y{}{}        Transliteration        no (but see below)
        <<EOF                 here-doc            yes*
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck