in reply to Re: Am I doing Greedy Matching?
in thread Am I doing Greedy Matching?

I do not want the domain name.. I just need the machine1-basement string in my array and hence the Regex. I just discovered the "/g" and will try it out and let you know.. Thanks !

Replies are listed 'Best First'.
Re^3: Am I doing Greedy Matching?
by jwkrahn (Abbot) on Nov 10, 2011 at 11:43 UTC

    OK, so change:

    push @sourceDBHostsFromTnsEntry, $record =~ /HOST=(\S+-\S+)/g;

    To:

    push @sourceDBHostsFromTnsEntry, $record =~ /HOST=(\w+-\w+)/g;
      Ah Perfect! I think I had missed the /g and hence the array with only one record. What you suggested worked perfectly! Thanks!

      I tried out the other responses as well.. they work too. I liked the simplicity of the foreach method - easy to understand, but its kinda long to type. I keep very descriptive variable names so as to make the code (variables and their purpose) easy to understand by another person who;s looking at my code. In fact, it helps me too, if I have to revisit my code after a year or two.

      Thanks all for your suggestions! Truly and highly appreciate your contributions :-)