XP is just a number | |
PerlMonks |
Re: Getting data from second file, based on first files contents;by kcott (Archbishop) |
on Oct 29, 2015 at 05:28 UTC ( [id://1146351]=note: print w/replies, xml ) | Need Help?? |
G'day james28909, "Anyway, let me start off by posting example code and files:" For future reference, please post a short, representative sample of your data here. I tried to download the zip file you linked to, but
[Perhaps I could've tried harder to get this but I don't really have the time and I shouldn't have to, anyway.] Here's some tips on the code you presented. When opening files, always check for problems. Either use the autodie pragma or hand-craft messages (see open for examples). Repeatedly opening files in a loop, and reading their entire contents multiple times, is rarely (if ever) a good idea. I see that you've done this in both a while and a for loop. Aim to open and read once. If you need to jump around in an opened file, consider seek and tell. When you read "file1" (for the first time), it may be better to store the data in a hash. For example, instead of
perhaps something closer to
You can then lose the "for (@original) {...}" loop altogether, and change
to something like
Also, your use of a regex match ($last =~ $_) seems questionable. I haven't delved too deeply into this, but a straight equality check ($last eq $_) looks like it might be a better idea. These suggestions have been intentionally vague. Without any input and only erroneous expected output (you wrote: "EDIT: It seems there is indeed an error in the output"), I am somewhat loathe to attempt to suggest anything more concrete with regards to the actually processing. If you do provide sample input and real expected output, myself (or another monk) might provide a better answer. — Ken
In Section
Seekers of Perl Wisdom
|
|