Re: Variable inside regular expression



mattwoolnough@xxxxxxxxx wrote:
Is it possible to use variables inside regex?

That's a very simple question, but you posted some not-so-simple code
to illustrate it.

One basic debugging technique that you should adopt is to write a
small, simple program that tests your question AND NOTHING MORE. That
will quickly and easily reveal if the problem is what you think it is
(that variables don't match in a regexp) or something completely
unrelated to that quesion.

Consider this code:

#!/usr/bin/perl
use strict; use warnings;

my $foo = 'foo';
my $string = "foobar";

print "YES" if $string =~ /$foo/;

__END__

Run it and find out the answer to your question. You could have
written this program and answered your own question with less time and
effort than it took you to ask it here.

--
David Filmer (http://DavidFilmer.com)

.