Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: print all data matching identical three alphabets from two different files

by kcott (Archbishop)
on Nov 15, 2017 at 23:22 UTC ( [id://1203534]=note: print w/replies, xml ) Need Help??


in reply to print all data matching identical three alphabets from two different files

G'day mao9856,

Here's another (less busy) way to do it.

#!/usr/bin/env perl use strict; use warnings; use Inline::Files; my %match; ++$match{substr $_, 0, 3} while <MATCH_DATA>; while (<PARSE_DATA>) { print if $match{substr +(split)[1], 0, 3}; } __MATCH_DATA__ ABCD12 XYZ13 EFGT45 UVWZ34 TSR78 __PARSE_DATA__ ID121 ABC14 ID122 EFG87 ID145 XYZ43 ID157 TSR11 ID181 ABC31 ID962 YTS27 ID529 EFG56 ID684 TSR07 ID921 BAMD80

Output:

ID121 ABC14 ID122 EFG87 ID145 XYZ43 ID157 TSR11 ID181 ABC31 ID529 EFG56 ID684 TSR07

I've used Inline::Files just to show the technique. It's good you've used the 3-argument form of open; but less good that you've used package variables for the filehandles — prefer lexical filehandles instead. Also, your error reporting (i.e. or die) is rubbish: either spend a lot more time on this tedious and error-prone task yourself, or just let Perl do it for you with the autodie pragma.

Please post data within <code>...</code> tags as you did with your code. This makes it a lot less work for you; your data isn't subject to HTML interpretation (e.g. special characters and whitespace compression); and it makes it a lot easier for us to paste it directly into any example code we might provide.

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-26 04:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found