in reply to Storing Regex Patterns in Scalars
Another way of doing this is to store a reference to your regex using qr(). For example,
#!/usr/bin/perl -w use strict; my $re = qr/hello/; my $string1 = "hello"; my $string2 = "good bye"; if($string1 =~ $re){ print "Match $string1\n"; } if($string2 =~ $re){ print "Match $string2\n"; }
|
|---|