Friends.. I'm newbie in perl and doing this practice test which is I'm not able finish... What I'm trying.. 1. Parse tnsfile and search for only first alias name from the line (first "IF" gets me this i.e. DB1.UK, DB1.EU, DB3.UK, DB3.US, DB5.UK.US) ... this lets me connect to each database But problem is this will also connect same database (SID = ??) multiple times and I don't want to do that Is there anyway to have $hashref store only single alias with distinct SID? 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)) ) DB5.UK.US, DB5.US = ( (ADDRESS = (PROTOCAL = TCP)) (CONNECT_DATA = (SID = db5)) )
Expected $hashref value:
DB1.UK DB3.UK DB5.UK.US

In reply to Perl parsing file by homer4all

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.