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?
$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.
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*
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.