in reply to Grep asterisk sign in input file

If the waiver file is relatively small, you can just translate the masks into regular expressions, store them in an array with their respective values, and apply them on each line. In the following code, only the first matching expression is applied, change the line containing last if that's not the expected behaviour.
#!/usr/bin/perl use warnings; use strict; my ($input, $waiver) = @ARGV; open my $fh_w, '<', $waiver or die "$waiver: $!"; my @filters; while (<$fh_w>) { my ($mask, $value) = split; $mask =~ s/\*/.*/g; push @filters, [ $mask, $value ]; } open my $fh_i, '<', $input or die "$input: $!"; while (<$fh_i>) { my ($key, $space, $value) = split /(\s+)/; for my $filter (@filters) { $value = $filter->[1], last if $key =~ /$filter->[0]/; } print "$key$space$value\n"; }
($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,

Replies are listed 'Best First'.
Re^2: Grep asterisk sign in input file
by Athanasius (Archbishop) on Jul 25, 2017 at 07:18 UTC

    Hello choroba,

    Nice solution, especially the inclusion of last which avoids a potentially nasty bug.

    But as it stands, this code will match a filter value such as ac* with an input value such as zac1234 — which doesn’t appear to be what the OP wants. This is easily fixed by anchoring the filter regex to the beginning of the match:

    $value = $filter->[1], last if $key =~ /^$filter->[0]/;

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,