<div dir="ltr">Greetings,<div><br></div><div>I find myself needing to use the value of a Moose Attribute in a regular expression every now and then.  Typically I accomplish this via (warning that all examples are very contrived and may contain bugs):</div><div><b><br></b></div><div><b>Sample Using Variable Assignment First</b></div><div><br></div><div><font face="monospace, monospace">my $value = $my_moose_object->attribute;</font></div><div><font face="monospace, monospace">if( $some_value =~ m/\Q$value/ ) {</font></div><div><br></div><div>Needless to say this isn't the most efficient/easiest to work with.  Given that fact, I've come across a way of using Moose Attributes directly in regular expressions:</div><div><br></div><div><b>MyObject</b></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">package MyObject;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">use Moose;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">has foo => ( is => 'ro', isa => 'Str' );</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">...;</font></div><div><br></div><div><b>Script That Consumes MyObject</b></div><div><br></div><div><font face="monospace, monospace">my $object = MyObject->new( foo => 'Value' );</font></div><div><font face="monospace, monospace">if( $some_value =~ m/\Q${\( $object->foo )}\E/ ) {</font></div><div><br></div><div><br></div><div>This works, but frankly I'm not entirely certain why.  From the documentation at <a href="http://perldoc.perl.org/perlre.html#Regular-Expressions" target="_blank">http://perldoc.perl.org/<wbr>perlre.html#Regular-<wbr>Expressions</a> I have:</div><div><br></div><div>\Q          quote (disable) pattern metacharacters until \E</div><div>\E          end either case modification or quoted section, think vi<br></div><div><br></div><div>Great, that makes sense.</div><div><br></div><div>But what magic is the ${\( ... )} doing here?  I'd be most grateful if anyone had some insight and could share it with us!</div><div><br></div><div>Best Regards,</div><div>Robert Stone</div><div><br></div><div><br></div></div>