Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
February 7, 2011, 7:27 am
rate this thread
I need some help for a scenario explained below.
File A has content as below:
-from logic.blocka.reg* -to logic.blockb.temp_reg*
-from logic.blockb.reg* -to logic.blockc.*reg*
-from logic.blockc.*reg* -to logic.blockb.reg*
File B has content as below:
Now i need to look into File A and for 1st line for example
"-from logic.blocka.reg* -to logic.blockb.temp_reg*"
Look into File B for the path name after 'from' and 'to' and then
prepare an output as below:
always @ (tb.device.logic.blocka.reg_0.Q)
always @ (tb.device.logic.blocka.reg_1.Q)
always @ (tb.device.logic.blocka.reg_2.Q)
always @ (tb.device.logic.blocka.reg_3.Q)
Thanks for your time..
Re: Comparison of 2 files and generating the output based on comparison
This is a typical data munging task. Pseudo code for your script is as
follows, at least as a first step:
open file A
for each line in file A
- split the line
- stuff the values into a suitable data structure (perhaps %A)
close file A
open file B
for each line in file B
- split the line
- stuff the values into a suitable data structure (perhaps %B)
close file B
iterate through %A
- if there is a match with an element of %B, print
From the appearance of your data, you could probably throw away the
first three directories, tb, device, and logic. It strikes me that (as
a first try) you might want to replace the delimiter in each line to a
common delimiter, perhaps a colon, save the whole thing as a string,
and then use a regular expression to match against the string.
From there, you can optimize, perhaps by just saving the values in the
first file as an array of strings, and directly match the values in
the second file without using a second data structure. This depends on
the nature of your data, and if your data is sorted in some kind of
way, the task become much easier.
Your question isn't a Perl question as such, but more of a general
question applicable to whatever language you would want to use,
although Perl can certainly handle this task with ease and speed.
- » FAQ 5.35 How do I close a file descriptor by number?
- — Previous thread in » PERL Discussions