in reply to Re^3: Retrieving Key and Value Hashes
in thread Retrieving Key and Value Hashes

i tried to simply insert my files instead. on the command line it didnt print anything. no syntax errors. been working through possible edits.

open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my %hash1 = split ' ', do{ local $/; <FILE1> }; close FILE1; open(FILE2, $ARGV[1]) or die "Cannot open the file: $!"; while(<FILE2>) { my ($key) = split; exists $hash1{$key} and print "$key $hash1{$key}\n"; } close FILE2;

Replies are listed 'Best First'.
Re^5: Retrieving Key and Value Hashes
by Laurent_R (Canon) on Jul 05, 2015 at 09:01 UTC
    Unless I missed something, your revised script (based on Anonymous Monk's suggestion) should work with the data you've shown. If it does not print anything, then, probably, the data is not exactly what you think.

    I would suggest that you add some debugging statements to the first part of your script, for example as follows:

    use Data::Dumper; open(FILE1, $ARGV[0]) or die "Cannot open the file: $!"; my %hash1 = split ' ', do{ local $/; <FILE1> }; close FILE1; print Dumper \%hash1;
    and provide the printed output (or part thereof if it is large).

    Update: Fixed a typo in the code above. Thanks to AnomalousMonk for having picked it and informed me.

Re^5: Retrieving Key and Value Hashes
by AnomalousMonk (Archbishop) on Jul 05, 2015 at 17:37 UTC

    Here's one approach:

    Data file 1 file_1.dat:

    Data file 2 file_2.dat:

    Script check_hash_vs_keys_1.pl:

    Output:

    c:\@Work\Perl\monks\gghelpneeded>perl check_hash_vs_keys_1.pl file_1.d +at file_2.dat 'name1' -> 'ABCD' 'name4' -> 'AAAAA'


    Give a man a fish:  <%-(-(-(-<

Re^5: Retrieving Key and Value Hashes
by Anonymous Monk on Jul 05, 2015 at 03:42 UTC

    What is REPMOD ?

      it was the name of the original file, changed it to make it generic. my mistake.