in reply to Wildcard in a hash
in thread Grep asterisk sign in input file
It works for your test case :)
#!/usr/bin/perl # http://perlmonks.org/?node_id=1196126 use strict; use warnings; my (%waiverhash, @waiverstar); open my $w, '<', \<<END or die; c4a_123,350.00,3300.00,"Justification","Waived,by","Waived,Date","Appr +oved,by","Approved,date" c4emib_*,250.00,2000.00,"Justification","Waived,by","Waived,Date","App +roved,by","Approved,date" END while(<$w>) { my ($name, $target, $adhust) = split /,/; if( $name =~ s/\*/.*/g ) { push @waiverstar, [ qr/^$name$/, $target, $adhust ]; } else { $waiverhash{$name} = [ $target, $adhust ]; } } close $w; while(<DATA>) { my ($name, $target, $adjust) = (split)[1 .. 3]; if( $waiverhash{$name} ) { $target == $waiverhash{$name}[0] and $adjust <= $waiverhash{$name} +[1] and s/VIOLATED/WAIVED/; } else { for my $star ( @waiverstar ) { if( $name =~ $star->[0] ) { $target == $star->[1] and $adjust <= $star->[2] and s/VIOLATED/WAIVED/; last; } } } print; } __DATA__ f1 c4a_123 350.00 3251.94 -2901.94 (VIOLATED) f1 c4b_123 350.00 2419.08 -2069.08 (VIOLATED) f2 c4emib_2060 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2061 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2062 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2063 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2064 250.00 2000.00 -1750.00 (VIOLATED) f2 c4emib_2065 250.00 2000.00 -1750.00 (VIOLATED)
|
|---|