Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PERL LOGIC

Status
Not open for further replies.

maxmave

Programmer
Jun 3, 2008
5
US
Hello All,

Currently i am working on a logic in PERL scripting ...

But i am sort of stuck up, can any one please help.

Here goes.

1. Search for a pattern in a file
2. If the pattern matched lets say 10 lines
2.1 Reterive the first line and check for another pattern
2.1.1 if the second pattern found
2.1.1.1 extract the characters between the patterns
2.1.1.2 if its numbers, replace it with another set of numbers provided as input.
2.2 Reterive the Second line and check for another pattern
2.2.1 if the second pattern found
2.2.1.1 extract the characters between the patterns
2.2.1.2 if its numbers, replace it with another set of numbers provided as input.
......................
2.10 Reterive the Second line and check for another pattern
2.10.1 if the second pattern found
2.10.1.1 extract the characters between the patterns
2.2.10.2 if its numbers, replace it with another set of numbers provided as input.



The Problem is i am not that much familiar with the PERL commands,i am trying to work on any help would be grateful.

Thanks

Rahul
 
What is your question?

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
# I think this is what maxmave is after
# NOTE: Please ignore the obvious flaws, this
# code should be considered starting point only.
$pat1 = "sounds like" ;
$pat2 = "a school project"

while ($input = <FH>) {
if ($input =~ /($pat1)(.*)($pat2)/) {
($pre, $sub_str, $post) = ($1,$2,$3) ;
if ($sub_str =~ /\d/) {
$new_val = <STDIN>;
$output = $pre . $new_val . $post ;
} else {
# no info provided for this case.
};
};
};
 
They have this question on a number of forums so I wouldn't waste too much effort.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top