if ($_ =~ $identifier{$pins1.}) {

This doesn't work. {$pins1.} is a syntax error. There is no wildcard lookup in a hash.

$vline =~ s/^\S+//; #trim leading space

Nope. \S is non-blank.

my (undef,$scenario, $pins1, $threshold1, $newthreshold1, $diff, $stat +us) = split /\s+/, $wline;

Your key is ending up in $scenario here. Skip the undef.

If you encounter an identifier with a wildcard in the waiver file, you need to rewrite that identifier as a valid perl regular expression and later match each key of the waiver hash against the current $pins1:

#! /tools/perl/5.8.8/linux/bin/perl use strict; use warnings; use Data::Dumper; # Source script my $report = $ARGV[1] ; my $waiver = $ARGV[3] ; my $result = $ARGV[5] ; # Set up a hash to receive the information my %identifier = (); # Read the violations file into the hash open my $filter, '<', $waiver or die; while (my $vline = <$filter>) { next unless $vline =~ /\S/; #skip blank lines print $vline; $vline =~ s/^\s+//; #trim leading space my ($pins2, $threshold2, $newthreshold2) = split /,/, $vline; $pins2 =~ s/\*$/.*/; # make key into regex string if trailing * $identifier{$pins2}{'threshold2'} = $threshold2; $identifier{$pins2}{'newthreshold2'} = $newthreshold2; } close $filter; print Dumper \%identifier; # Read input file line by line and compare 2 files open my $input, '<', $report or die; open my $output, ">", $result or die; while (my $wline = <$input>){ my ($scenario, $pins1, $threshold1, $newthreshold1, $diff, $status +) = split /\s+/, $wline; # overwrite values if match for my $key(keys %identifier) { if ($pins1 =~ /^$key$/) { if ( ($threshold1 == $identifier{$key}{'threshold2'}) && ( +$newthreshold1 <= $identifier{$key}{'newthreshold2'}) ) { $status = '(WAIVED)'; } last; # skip remaining keys of for()-loop } } printf $output "%-44s %-24s %-8s %-8s %-8s %-10 +s\n", $scenario, $pins1, $threshold1, $newthreshold1, + $diff, $status; } close $input; close $output;

Close your filehandles as soon as you are done with them.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

In reply to Re: Wildcard in a hash by shmem
in thread Grep asterisk sign in input file by DespacitoPerl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.