Grepping on special characters


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

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.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

$OUTDOCOND = "$EGH0001_#SSSR0002_OK";
Should be
$OUTDOCOND = ‘$EGH0001_#SSSR0002_OK’;
$OUTDOCOND = q"$EGH0001_#SSSR0002_OK";

\# does not need \

perl -Mdiagnostics  -e '$OUTDOCOND = "$EGH0001_#SSSR0002_OK"'
Name "main::EGH0001_" used only once: possible typo at -e line 1 (#1)
    (W once) Typographical errors often show up as unique variable
    names.  If you had a good reason for having a unique name, then
    just mention it again somehow to suppress the message.  The our
    declaration is also provided for this purpose.
    NOTE: This warning detects package symbols that have been used
    only once.  This means lexical variables will never trigger this
    warning.  It also means that all of the package variables $c, @c,
    %c, as well as *c, &c, sub c{}, c(), and c (the filehandle or
    format) are considered the same; if a program uses $c only once
    but also uses any of the others it will not trigger this warning.
    Symbols beginning with an underscore and symbols using special
    identifiers (q.v. perldata) are exempt from this warning.
Use of uninitialized value $EGH0001_ in concatenation (.) or string at -e line
      1 (#2)
    (W uninitialized) An undefined value was used as if it were already
    defined.  It was interpreted as a "" or a 0, but maybe it was a mistake.
    To suppress this warning assign a defined value to your variables.
    To help you figure out what was undefined, perl will try to tell you
    the name of the variable (if any) that was undefined.  In some cases
    it cannot do this, so it also tells you what operation you used the
    undefined value in.  Note, however, that perl optimizes your program
    and the operation displayed in the warning may not necessarily appear
    literally in your program.  For example, "that $foo" is usually
    optimized into "that " . $foo, and the warning will refer to the
    concatenation (.) operator, even though there is no . in
    your program.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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*
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.