Perl string parsing -


friends...

i'm trying parse string in perl.

for last couple of classes i'm testing oracle tns file , testing variations, particular small if code taking time, please suggest?

basically if statement, i'm trying read tns file , put single value in hash reference till if statement gets expected result...

  1. get single alias value tns line
  2. get sid of alias
  3. put distinct sid value hash reference connect database once , not multiple times.

first if works connects couple of databases multiple times.

code:

if /^(([a-za-z][a-za-z0-9]*)(\.([a-za-z][a-za-z0-9]*))*)(\s|,|=)/ {   (/\(connect_data\s+=\s+\(sid\s+=\s+(\w+\d+?)(\s+)?\)/)     {         $hashref->{$1}="";     } } 

sample file (tnsfile.txt)

db1.uk, db2.uk =   (     (address = (protocal = tcp))     (connect_data = (sid = db1))   )  db1.eu, db2.ch =   (     (address = (protocal = tcp))     (connect_data = (sid = db1))   )  db3.uk =   (     (address = (protocal = tcp))     (connect_data = (sid = db3))   )  db3.us =   (     (address = (protocal = tcp))     (connect_data = (sid = db3))   )  db4.uk.us, db5.us =   (     (address = (protocal = tcp))     (connect_data = (sid = db5))   ) 

expected result:

db1.uk  db3.uk  db4.uk.us 

the regex should be

/(^[a-za-z0-9.]+)/ 

i.e. string, anchored @ start of line containing 1 or more alphanumeric characters or dots. if want more specific ignoring lines string starts or ends dot you'd have more complex, not needed if file valid tns file.

here's more complete regex matches valid strings

/^(([a-za-z][a-za-z0-9]*)(\.([a-za-z][a-za-z0-9]*))*)(\s|,|=)/ 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -