I want to read a file from a point where a regular expression matches and keep on reading till i hit another regular expression; while reading this part of the file ( binary strings of known size; search the appropriate position, parsed through a fil, make a replacement);
10 1899
Look theres that Line that im looking for look right there thats the line right there
you cant see it ???
what have you attempted so far?
Adding more to what I wrote earlier:
there are two input file: used in step 1) & 3) and second one at step 2
parsed the input file which basically gives me three variables;
out of three varibles two are regular expression and one integer,
I match the first regular expression then after two line i have hard coded expression then i match my second regular expression from this point onwards there are strings of binaries in multiple line and i need to count the bits to the value equal to third variable (integer) and replace with known character;
then i pick another line from input file and repeatt the same process;
In short here is what i have done (step 1 &3) and where i am stuck (step 2 ):
1)Open and read first line of inputfile1 which gives a string and eventually three variables
2) two are regular expression one integer; use them to rplace the binary with know character; i am stuck as to how i read and replace the binary with know character
3) repeat 2 with next line from input file
I have done 1) & 3).............missing the heart of the problem step 2)
I parsed the input file which basically gives me three variables;
out of three varibles two are regular expression and one integer,
I match the first regular expression then after two line i have hard coded expression then i match my second regular expression from this point onwards there are strings of binaries in multiple line and i need to count the bits to the value equal to third variable (integer) and replace with known character;
then i pick another line from input file and repeatt the same process;
in short here is what i have done and where i am stuck:
1)Open and read first line of inputfile1 which gives a string and eventually three variables
2) two are regilar expression one integer; use them to rplace the binary witj know character
3) repeat 2 with next line from input file
I have done 1) & 3).............missing the heart of the problem step 2)
Post the code you have written so far.
I am completely new to Perl so plaese provide me the tips for efficient codind as well.........here is sample of the code has been written so far -
open(INP2, "<$patFile") || die "Unable to open (-i) $patFile for input";
-
open(INP1, "<$msffFile") || die "Unable to open (-i) $msffFile for input";
-
#open (WR, ">$OutFile") || die "cannot open $OutFile for writing \n";
-
-
$scan_op = "0";
-
$read_mss_operation = 0;
-
@arr_msff = "";
-
@arr_pat = "";
-
-
while (<INP1>) {
-
-
push(@arr_msff, $_);
-
#Format is:
-
#1 ch_0 47
-
}#
-
-
#Read and store file2
-
while (<INP2>) {
-
#file format is:
-
# ..........
-
# ..........other lines in the file
-
# SCAN = 1 ==> EXP as number (scan_op)
-
# APPLY "grp0_unload" 0 =
-
# CHAIN "ch_0" = "0101010100101010... \
-
# 010100101000010100...\
-
# .....
-
# ......
-
# CHAIN "ch_1" = ""0101010100101010... \
-
# 010100101000010100...\
-
# .. ....
-
# .. ....
-
# END;
-
push(@arr_pat, $_);
-
}
-
&get_msff_line();
-
#//End of main function
-
################################### Sub routines###########################
-
-
sub get_msff_line {
-
-
while ($read_mss_operation <= $#arr_msff){
-
my $one = get_msff_info($read_mss_operation) ;
-
chomp($one);
-
my ($scan_op,$ch_num,$mask_bit) = split (/ /,$one);
-
print "Scan Operation = $scan_op Chain number = $ch_num Masking Flop = $mask_flop" ;
-
print "\n";
-
-
-
# Logic for Finding and replacing the bit in the inputfile2 for $scan_op for $mask_bit in $ch_num
-
-
foreach ($i=0; $i <$#arr_pat; $i++){
-
chomp $arr_pat[$i];
-
if ($arr_pat[$i] =~ m/SCAN = $scan_op/){
-
-
print "$arr_pat[$i]\n";
-
}
-
-
}
-
$read_mss_operation++ ;
-
}
-
}
-
-
sub get_msff_info() {
-
$get_line = $_[0];
-
return $arr_msff[$get_line] ;
-
}
-
I am completely new to Perl so plaese provide me the tips for efficient codind as well.........here is sample of the code has been written so far
well
first off if your going to post code please use code tags it helps the experts read the code a lot easier if you want this solved then use code tags, i have missed a few errors in the script because of no code tags, so please use code tags.
second:
this could be a problem - while ($read_mss_operation <= $#arr_msff){
try - while ($read_mss_operation <= $arr_msff){
i have to leave for about 1 hr so ill continue to look at the rest of the script.
Thank You,
well
first off if your going to post code please use code tags it helps the experts read the code a lot easier if you want this solved then use code tags, i have missed a few errors in the script because of no code tags, so please use code tags.
second:
this could be a problem - while ($read_mss_operation <= $#arr_msff){
try - while ($read_mss_operation <= $arr_msff){
i have to leave for about 1 hr so ill continue to look at the rest of the script.
Thank You,
Icecrack,
arr_msff is an array variable (@arr_msff). $#arr_msff is used to get the last index of the array. That is not the problem.
In short here is what i have done (step 1 &3) and where i am stuck (step 2 ):
1)Open and read first line of inputfile1 which gives a string and eventually three variables
2) two are regular expression one integer; use them to rplace the binary with know character; i am stuck as to how i read and replace the binary with know character
3) repeat 2 with next line from input file
I have done 1) & 3).............missing the heart of the problem step 2)
To search for a pattern and replace it with any other character, you may use substitution operator(s///). -
s/$search_pattern/replacement/ ;
-
Also, note the following:
1. If the words in your input file are separated with multiple spaces, replace -
my ($scan_op,$ch_num,$mask_bit) = split (/ /,$one);
-
with: -
my ($scan_op,$ch_num,$mask_bit) = split (/\s+/,$one);
-
2. There is no need of using a while loop to read from the file and push the lines to an array. You can directly use: -
@arr_msff = <INP1>;
-
@arr_pat = <INP2>;
-
Icecrack,
arr_msff is an array variable (@arr_msff). $#arr_msff is used to get the last index of the array. That is not the problem.
thanks for the update never knew Perl did that with the array.
Learn Something new every day.
I get you are reading one file and that you need to use the data in the file to replace something in the other file, but what is it you are replacing?
Sign in to post your reply or Sign up for a free account.
Similar topics
by: William Holroyd |
last post by:
I've had experience with PHP building simple websites and have only
scratched the surface of what it's capable of, so in a sense I'm a newbie.
However the problem I have is that I want to be able...
|
by: Follower |
last post by:
Hi,
I am working on a function to return extracts from a text document
with a specific phrase highlighted (i.e. display the context of the
matched phrase).
The requirements are:
* Match...
|
by: Tom Deco |
last post by:
Hi,
I'm trying to use a regular expression to match a string containing a #
(basically i'm looking for #include ...)
I don't seem to manage to write a regular expression that matches this.
...
|
by: Steve Kirsch |
last post by:
I need a simple function that can match the number of beginning and ending
parenthesis in an expression. Here's a sample expression:
( ( "john" ) and ( "jane" ) and ( "joe" ) )
Does .NET have...
|
by: Chris |
last post by:
Hi Everyone,
I am using a regex to check for a string. When all the file contains is my
test string the regex returns a match, but when I embed the test string in
the middle of a text file a...
|
by: Johnny Williams |
last post by:
I'm struggling to create a regular expression for use with VB .Net which
matches a person's name in a string
of words.
For example in "physicist Albert Einstein was born in Germany and"
I want...
|
by: cmk128 |
last post by:
Hi
PHP's regular expression look like doesn't support .*? syntax. So i
cannot match the shortest match. For exmaple:
$str="a1b a3b";
$str1=ereg_replace("a.*b", "peter", $str1);
will produce...
|
by: Peng Yu |
last post by:
Hi,
The following code snippet is from /usr/bin/rpl. I would like the it
to match a word, for example, "abc" in ":abc:". But the current one
would not match "abc" in ":abc:". I tried to modify...
|
by: Andy B |
last post by:
I need to create a regular expression that will match a 5 digit number, a
space and then anything up to but not including the next closing html tag.
Here is an example:
<startTag>55555 any...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |