Regexp help

M

mike

Hi,

I am using the following to find matches in a file.

open( PLUGINS, $pluginsBase ) or die "can't open $pluginsBase, $!\n";
while (<PLUGINS>) {

#Since list command shows both enabled and disabled versions of the plugin. Exclude disabled version in version check.
if ( /\$id/ && !/disable/ ) {


}

}


Problem I have is that when $id is equal to org.erlide it will also match contents of the file like:

org.erlide.trace
org.erlide.debug

How can I match the exact:

org.erlide

Nothing more nothing less.

br,

//mike
 
M

mike

I tried it but I does not match at all. Here is an example of three lines that I read:

Feature: org.eclipse.equinox.p2.user.ui 2.1.2.R37x_v20110815-1155-6-Bk8pYWZz0qUTX5I15GZWwbXkrl enabled
Feature: org.erlide.tracing 0.2.2.201204301337 enabled
Feature: org.erlide 0.16.0.201204301337

we should only match org.erlide this exactly.

br,

//mike
 
M

mike

Oh, seeing the actual data would have helped azrazer ...

# assuming that $id is set to "org.erlide", then
if ( /\s$id\s/ && !/disable/ ) {

Or even more explicitly, assuming that all your data is as you've shown
if ( /^Feature: $id\s/ && !/disable/ ) {

BTW you'd coded /\$id/; that will match the string "$id", not the value
of the variable $id;

Thanks that worked out fine. Sorry azrazer for leaving out essential information.

//mike
 
J

Jürgen Exner

No, you don't want to match, you want to test for equality.
Oh, seeing the actual data would have helped azrazer ...

# assuming that $id is set to "org.erlide", then
if ( /\s$id\s/ && !/disable/ ) {

Yeah, right. Why do people, including the OP, insist on using REs for
comparing text? And you fell into the same trap, too.

Your suggestion will match e.g.
orgXeclipse
too, and I don't think this is what the OP wants.

Yes, this again can be patched by using quotemeta, but why?
If you want to check two strings for equality then just do so instead of
fumbling around with REs:

(undef, $domain, $code, $status) = split($_, ' ');
if ($domain == $id and $status!='disable') {
....
}

jue
 
J

Jim Gibson

J¸rgen Exner said:
If you want to check two strings for equality then just do so instead of
fumbling around with REs:

(undef, $domain, $code, $status) = split($_, ' ');
if ($domain == $id and $status!='disable') {
....
}

But please do use the string comparison operator:

if ($domain eq $id ...
 
J

Jürgen Exner

Ben Morrow said:
^^ ^^
Um, you were saying something about falling into traps?

Ummm, yeah, that happens when coding in several similar but not quite
identical languages at the same time.

Thanks for catching it.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top