Kenneth Brun Nielsen wrote: > > I need to make a conditional on a regular expression match. How can I > do that? > > E.g. in the code below, it prints all lines, and NOT only the ones > that match. How can I make the boolean test correct? > > #!/usr/bin/perl -w > open FILEHANDLE, "soatest.soa"; > while (<FILEHANDLE>){ > if (/^\*| XI/) { > print "match in line: $.\n"; > } > }
The regular expression /^\*| XI/ matches strings that either start with an asterisk or contain ' XI' anywhere. If you want to match strings that start with either an asterisk or ' XI' then you need /^(?:\*| XI)/ It looks messy, but (?: ... ) is simply non-capturing parentheses. You could use /^\*|^ XI/ instead if you prefer. If you wanted something different from that you must let us know. HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/