Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: comparing an ID fom one file to the records in the second file

by sundialsvc4 (Abbot)
on Dec 01, 2017 at 22:59 UTC ( [id://1204693]=note: print w/replies, xml ) Need Help??


in reply to comparing an ID fom one file to the records in the second file

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^2: comparing an ID fom one file to the records in the second file
by stevieb (Canon) on Dec 01, 2017 at 23:30 UTC

    You said:

    my $keys = {}; while (<FILEHANDLE>) {chomp; $keys[$_] = 1;}

    $keys is not an array, you've defined it as a hash reference. You meant $keys->{$_} ....

    Then you said:

    exists($keys, $recordArray[2])

    exists() does not work like that.

    exists $keys->{$recordArray[2]};

    Please, if you don't test the code you supply, acknowledge that in writing.

Re^2: comparing an ID fom one file to the records in the second file
by Laurent_R (Canon) on Dec 02, 2017 at 10:02 UTC
    Hi sundialsvc4,

    I think that in my approach to this problem I would “flip” it: let the second file drive the show, not the first!

    Since your first file appears to contain nothing other than a list of “keys of interest,” let’s start the show by a simple loop that adds each key to a hash with a do-nothing value.

    Just in case you didn't notice, that's exactly the approach suggested earlier by both poj and myself. I even explicitly explained that there were two possible approaches and that, in this case, it was probably a bit better to store the keys taken from the first file in the hash. Although, to tell the truth, choosing between the two approaches would require to know more about the respective size of the files. If the second file is much shorter than the first one, it might be better to choose the other way around.

Re^2: comparing an ID fom one file to the records in the second file
by karlgoethebier (Abbot) on Dec 03, 2017 at 11:13 UTC
    "...my approach to this problem..."
    "One Step Forward, Two Steps Back" (Vladimir Ilyich Lenin)

    See also

    «The Crux of the Biscuit is the Apostrophe»

    perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1204693]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-24 11:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found