in reply to Re^2: Wildcard in a hash
in thread Grep asterisk sign in input file

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'

Replies are listed 'Best First'.
Re^4: Wildcard in a hash
by DespacitoPerl (Acolyte) on Aug 16, 2017 at 02:25 UTC
    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]
      thanks, but in the loop of read input file, "if ($pins1 =~ /^$key$/) ", the dollar sign, $ will have to be removed too.

      This applys only if you want a partial match of the keys. A key like c4a would then match c4a_123[3] also.

      You could escape the brackets:

      $pins2 =~ s/\*/.*/; # make key into regex string if containing * $pins2 =~ s/([\[\]])/\\$1/g; # escape brackets c4a_123[3] -> c4a_1 +23\[3\]

      That way the brackets aren't treated as a character class whilst matching the keys.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        sry, what if in waiver file like this,
        *bump*,175.00,2000.00 *bump*,250.00,2000.00
        in original code, it will take the second one as reading, how can make it so that it ca read through both lines