As far as i can see, yes you are greedy-matching.
Before i start: You don't seem to use strict; and use warnings;, neither the 3-argument version of open, nor checking if open actually worked. Filehandles should also be written as scalars ("$hello") - which you would have noticed when using strict.
I'm a bit oldstyle, i would do it like this:
my @sourceDBHostsFromTnsEntry; my @sourceDBPortsFromTnsEntry; open(my $SOURCETNS, "<", "/home/$User/Work/PROJ/$sourceTnsFileName") o +r die($!); while((my $record = <$SOURCETNS>)) { chomp ($record); my @parts = split /\ /, $record; foreach my $part (@parts) { if($part =~ /HOST=(.*)/o) { push @sourceDBHostsFromTnsEntry, $1; } if($part =~ /PORT=(.*)/o) { push @sourceDBPortsFromTnsEntry, $1; } } } close($SOURCETNS);
I didn't test this specific code and there are probably "nicer" ways to do it but it should get the job done (although there may be the odd typo).
Explanation: In the first step, i read in a line and chop it up on the "space" delimeter into @parts. Then, foreach $part in @parts i match against the two tags "HOST=" and "PORT=". If it matches, i put the remainder into their respective arrays.
In reply to Re: Am I doing Greedy Matching?
by cavac
in thread Am I doing Greedy Matching?
by vishi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |