Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: How to compare hash values to array values in Perl

by kcott (Archbishop)
on May 14, 2014 at 05:18 UTC ( [id://1085977]=note: print w/replies, xml ) Need Help??


in reply to How to compare hash values to array values in Perl

G'day To_Bz,

Welcome to the monastery.

You can achieve that much more simply like this:

my %vals = map { $_ => 1 } <FILE2>; print $_->[0] for grep { $vals{$_->[1]} } map { [ split / / ] } <FILE1 +>;

I would, however, recommend you use lexical filehandles. See open for examples.

Here's my test (in the spoiler):

#!/usr/bin/env perl -l use strict; use warnings; use Inline::Files; my %vals = map { $_ => 1 } <VALUES>; print $_->[0] for grep { $vals{$_->[1]} } map { [ split / / ] } <TABLE +>; __TABLE__ xanmn_chr09_0114-xanmn_chr09_0114 3346 xanmn_chr09_0129-xanmn_chr09_0129 3358 xanmn_chr09_0116-xanmn_chr09_0116 3348 xanmn_chr09_0127-xanmn_chr09_0127 3354 __VALUES__ 3346 1933 1371 1448 2762 1395

Output:

xanmn_chr09_0114-xanmn_chr09_0114

See also: Inline::Files

-- Ken

Log In?
Username:
Password:

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

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

    No recent polls found