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

Please help us help you better and show representative input data.

Also note that one of the two lines here makes no sense, because they both define a variable @RecLine:

my @RecLine=split (/;/) ; my @RecLine=split ('\t') ;

Also note that split uses a regular expression to split on, not a string.

Your code, as shown will never produce any output because you never call Read_File.

Replies are listed 'Best First'.
Re^2: Printing hash key shows obscure values - can this be trimmed/removed?
by yasmarina (Initiate) on Apr 28, 2015 at 13:10 UTC
    I've commented out
    # my @RecLine=split (/;/) ; my @RecLine=split ('\t') ;
    Here's the rest of the code:
    my $Key=$NR ; my $Cmp=$CHARGE ; my $Key2=$INVOICE_TXT; sub Read_File { my $FILE = shift ; open (my $fh, "<", $FILE) || die "$!" ; my %hRec ; while (<$fh>) { chomp; #my @RecLine=split (/;/) ; my @RecLine=split ('\t') ; $CmpKey=$RecLine[$Key] ; $CmpKey2=$RecLine[$Key2] ; $CmpValue=$RecLine[$Cmp] ; $hRec{$CmpKey,";",$CmpKey2}=$CmpValue; } return (%hRec) ; } my %hBase=Read_File($ARGV[0]) ; my %hPost=Read_File($ARGV[1]) ; my $FILE_DATE=`date "+%Y%M%d_%H%M_%S"` ; chomp ($FILE_DATE) ; my $OUT_FILE="/tmp/CMP_OUT_$FILE_DATE.txt" ; open ( OFILE, "> $OUT_FILE" ) or die "FATAL ERROR! Unable to write fil +e(!)\n" ; ## Debug ## #chomp($key); #foreach my $key (sort {$a<=>$b} keys %hBase) { print "$key -> $hBase +{$key}\n"; } #foreach my $key (sort {$a<=>$b} keys %hPost) { print "$key -> $hPost +{$key}\n"; } foreach my $key (sort {$a<=>$b} keys %hPost) { $count=$count+1 ; if ($hBase{$key} ne $hPost{$key}) { #my $out_counter = "\n##Comparing _$ARGV[0] vs. $ARGV[1]_ differ +ences(!) in record: $count##\n" ; my ($recnos, $vINVOICE_TXT) = split (';', $key) ; chop ($recnos) ; $vINVOICE_TXT=~s!^.!!; my $vInv= "\"$vINVOICE_TXT\"" ; my $Rec=`egrep ^$recnos"\t"\$recnos.*$vInv $ARGV[0]` ; my $out_baseline = "\n$ARGV[0]:\n$HEADER\n$Rec" ; my $Rec=`egrep ^$recnos"\t"\$recnos.*$vInv $ARGV[1]` ; my $out_compare="\n$ARGV[1]:\n$HEADER\n$Rec" ; my $out_result="\n$ARGV[0] [$key -> $hBase{$key}] do not match(! +) with $ARGV[1] [$key -> $hPost{$key}] in record: $count\n" ; print OFILE "$out_result $out_baseline $out_compare " ; print "$out_result $out_baseline $out_compare " ; } } close ( $FILE ) ; close ( OFILE ) ;
    Note that I've added bits to trim off the obscure values:
    my ($recnos, $vINVOICE_TXT) = split (';', $key) ; chop ($recnos) ; $vINVOICE_TXT=~s!^.!!; my $vInv= "\"$vINVOICE_TXT\"" ;
    Am hoping to find a better way... Second to that, I used UNIX 'egrep' to extract the record. Am hoping to find a better way using perl code. Thanks
Re^2: Printing hash key shows obscure values - can this be trimmed/removed?
by yasmarina (Initiate) on Apr 28, 2015 at 12:57 UTC

    Test data (input file):

    1 1 11412 00353xxxxxxxxx 100 1017 00353xxxxxxxxx Voice - Na +t Free Call FREE::VOICE 01-DEC-11 20-NOV-11 600 0 0 + 0 0 0 0 0 0 0,[ ],[ ],[ ]|0,[ ],[ ],[ ]|0,[ ],[ +],[ ] Non-FU 0 National and International Voice Calls
    It's tab delimited. Hence I'm just looking to extract the 1st, 15th and 26th fields. 2 files will be read. 1st & 26th field will be my key. Field 15th is the value I'm comparing against the 2 fields. Any differences will be reported.