LoginSignup
3
2

More than 5 years have passed since last update.

正規表現にuse constantした定数を埋め込む

Posted at

use constant TEST_HOGE => 'hogehoge'; としていて、この定数をつかって正規表現をつくりたい場合。

普通に /TEST_HOGE/ とかすると TEST_HOGE という文字列とのマッチングになってしまいます。

なので、こうすると良いようです。

use constant TEST_HOGE => "hogehoge";

if ('hogehoge fugafuga'=~ /${\(TEST_HOGE)}/) {
    print "matched!";
}

参考
http://www.perlmonks.org/?node_id=104059

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2