in reply to Wildcard in a hash
in thread Grep asterisk sign in input file

Your question is very vague. It's not even clear what domain you're working in. Just for the interest of the other Monks, I'm going to guess that "emi" in your example file stands for electromagnetic interference, and that "ports/pins" are locations where you're applying and/or measuring some kind of test signal in a piece of hardware.

You talk about asterisks in your question, but your example doesn't contain any. Your other post was more understandable in that regard. But what if your waiver file contains these two lines:

c4*_123
c4a_*

If the input is c4a_123, which pattern should match? The first one? In that case, you need to remember the order of the waiver file, so you don't want to use a hash. See choroba's response to your original post.

Replies are listed 'Best First'.
Re^2: Wildcard in a hash
by choroba (Cardinal) on Jul 27, 2017 at 14:39 UTC
    > but your example doesn't contain any.

    It does:

    c4emib_*,250.00,2000.00,"Justification","Waived,by","Waived,Date","App +roved,by","Approved,date" ^ | here

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^2: Wildcard in a hash
by DespacitoPerl (Acolyte) on Aug 15, 2017 at 08:10 UTC
    The wildcard can be anywhere, Let say if meet case like c4*_123, how i going to write?

      See perlre. In perl regular expression syntax, the asterisc * is a quantifier which means "zero or more times" .

      So, in c4*_123 the asterisc would mean "zero or more times 4". To make the * into a wildcard, preceed it with a period, which means "any character". In my previous answer in this thread, there was the line

      $pins2 =~ s/\*$/.*/; # make key into regex string if trailing *

      The dollar sign after the escaped asterisc is an end anchor, so this matches only an asterisc at the end of the string. To match the asterisc anywhere, just remove the end anchor:

      $pins2 =~ s/\*/.*/; # make key into regex string if containing *

      If your keys can contain more than one asterisc, add the /g modifier (global) to the s///:

      $pins2 =~ s/\*/.*/g; # make key into regex string if containing *
      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        thanks, but in the loop of read input file, "if ($pins1 =~ /^$key$/) ", the dollar sign, $ will have to be removed too. I forget to mention that for the pins/ports name, it has expression like this symbol, [], which means that it cant be cathed when using ur way. This is the only weak point.
        For example, c4a_123[3]