in reply to Re: Printing hash key shows obscure values - can this be trimmed/removed?
in thread Printing hash key shows obscure values - can this be trimmed/removed?

$hRec{$CmpKey.";".$CmpKey2}=$CmpValue;
That works. Thank you. Any suggestion to avoid using UNIX system call 'egrep' to extract those records which do not match? i.e:
my ($recnos, $vINVOICE_TXT) = split (';', $key) ; .... .... .... my $Rec=`egrep ^$recnos"\t"\$recnos.*$vInv $ARGV[0]` ;
Once the differences have been identified, I split the key into 2 variables. Then attempt to grep the record from the input file to display the full record.

Replies are listed 'Best First'.
Re^3: Printing hash key shows obscure values - can this be trimmed/removed?
by hdb (Monsignor) on Apr 28, 2015 at 13:32 UTC

    egrep has a -v flag...

      Am looking to read into 2 tab-delimited files. Build a key and compare values. Those differences are output. I'd like to know an easier way to print the entire record of the differences as opposed to using UNIX grep via the key.

        Still not sure what you are looking for...

        use strict; use warnings; my %hBase = ( 'a;a' => 1, 'b;b' => 2, 'c;c' => 3 ); my %hPost = ( 'a;a' => 1, 'b;b' => 3, 'd;d' => 4 ); my %allKeys = map {$_=>1} keys %hBase, keys %hPost; for my $key (keys %allKeys) { if( exists $hBase{$key} and exists $hPost{$key} ) { if( $hBase{$key} eq $hPost{$key} ) { print "$key in both hashes with same value $hBase{$key}\n"; } else { print "$key in both hashes with different values $hBase{$key} != + $hPost{$key}\n"; } } else { print "$key in %hBase with value $hBase{$key}\n" if exists $hBase{ +$key}; print "$key in %hPost with value $hPost{$key}\n" if exists $hPost{ +$key}; } }
Re^3: Printing hash key shows obscure values - can this be trimmed/removed?
by Laurent_R (Canon) on Apr 28, 2015 at 20:10 UTC
    Sure, Perl's grep built-in function is very powerful, in fact generally much more powerful than Unix' egrep (to tell the truth, they are not used exactly the same way, Perl's grep works on a Perl array, not exactly the same thing as Unix's egrep working usually on files or data flow), in part because Perl's regexes are incredibly good (and far beyond the "official" definition of regular expressions).

    In your case, I am fairly sure that Perl's grep function should do what you want much more efficiently than a system call to egrep, but I am not very clear on what you are really trying to achieve, so I can't help further for the time being. Please specify what you need.

    Je suis Charlie.