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

i have a secondary question. i modified it to work with a bigger file and it appeared not work. is there a way to integrate what you are scripting into my script?

Replies are listed 'Best First'.
Re^3: Retrieving Key and Value Hashes
by AnomalousMonk (Archbishop) on Jul 05, 2015 at 01:18 UTC
    is there a way to integrate what you [AnonyMonk] are scripting into my script?

    As the AnonyMonk says, it's a here document (see also the discussion of here-docs in Quote and Quote-like Operators in perlop), another way of defining a Perl string. To use the AnonyCode in your program, open the files by the name of an external file (not by reference to an internal string) just as you were doing in your OPed script.

    i modified it ... and it appeared not work.

    Problem descriptions like "it doesn't work" are almost useless. Can you please be more specific? How does it not work? Please see I know what I mean. Why don't you?.


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

      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;
        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.

        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:  <%-(-(-(-<

        What is REPMOD ?

Re^3: Retrieving Key and Value Hashes
by Anonymous Monk on Jul 05, 2015 at 00:19 UTC

    Probably.