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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pattern Matching 1

Status
Not open for further replies.

rafiu

Programmer
Jul 3, 2007
14
US
Is there anyway to better match a line that started with a dot from the begining to the end of the close parenthesis?Below is a sample from the file:
.upper_house3({located in east valley}) \\good neigbourhood
.upper_house1({located in east valley}) \\good neigbourhood
.upper_house2({located in east valley}) \\good neigbourhood




I tried using the code below but it won't work:

open (file, "c:\\text.txt");
while (<file>)
{
if ($_ = /^(\.upper_house3).*(\))/)
{
$good_location = $_;
print "$good_location\n";
}
}
 
From your description, try this:

/^\..*\)/

From the code you provided it seems that you only want to match for upper_house3. If that is the case, try:

/^\.upper_house3.*\)/

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
You are using the assingment operator "=" when you should be using the binding operator "=~":

Code:
if ($_ [red]=~[/red] /^(\.upper_house3).*(\))/)

or you can write it like this:

Code:
if (/^(\.upper_house3).*(\))/)

in which case the "$_ =~" part is implied.

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

Part and Inventory Search

Sponsor

Back
Top