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
In reply to Re: print all data matching identical three alphabets from two different files
by kcott
in thread print all data matching identical three alphabets from two different files
by mao9856
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |