in reply to Re^2: find common data in multiple files
in thread find common data in multiple files
"This code worked for me after I put last line ... before closing parenthesis. Thanks a million"
Whilst I appreciate the thanks, it sounds like you've introduced a (possibly subtle) bug. The basic logic for my code is:
Declare hash SINGLE BLOCK (reading one file): Populate hash LOOP BLOCK (reading all other files): Remove data that isn't common from hash Print hash data
If you move the Print operation to LOOP BLOCK, you'll get multiple (24) groups of output. That's not what you want, and it would have been plainly obvious if you'd done that, so you've probably done something different to what you've described.
You've said "I am very beginner of perl" in a couple of places. I suspect you haven't understood the anonymous block I used in SINGLE BLOCK and ended up with logic more like this:
Declare hash start SINGLE BLOCK Populate hash LOOP BLOCK Print hash data end SINGLE BLOCK
An anonymous block is just code wrapped in braces:
{ # code here }
I've used it to provide a limited lexical scope. The variables ($fh, $k and $v) that I've declared in that block, only exist in that block; they are quite different to, and cannot interfere in any way with, the similarly named variables elsewhere in the code. There's also an additional benefit: when $fh goes out of scope, Perl performs an implicit close.
Anyway, while that's probably useful information you can add to your "beginner of perl" knowledgebase, it's very much guesswork on my part with respect to whatever modifications you made to my original code. If you post your changes, I can provide more concrete feedback.
— Ken
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^4: find common data in multiple files
by mao9856 (Sexton) on Dec 31, 2017 at 06:09 UTC | |
by kcott (Archbishop) on Jan 01, 2018 at 01:01 UTC | |
by poj (Abbot) on Dec 31, 2017 at 09:18 UTC | |
by mao9856 (Sexton) on Jan 01, 2018 at 05:08 UTC | |
by AnomalousMonk (Archbishop) on Jan 01, 2018 at 05:56 UTC |