<div dir="ltr">Greetings,<div><br></div><div>You are correct in the sense that $object->foo actually calls a method "foo" created via Moose Magic that returns the value of the foo attribute.  Good call!</div><div><br></div><div>Are you thinking that given the above, the \( ) business makes $object->foo a coderef, and then ${ } executes it because it dereferences it?  Given that, why does this not match:</div><div><br></div><div><span style="font-family:monospace,monospace;font-size:12.8px">if( $some_value =~ m/\Q$object->foo\E/ ) {</span><br></div><div><br></div><div>While this does:</div><div><br></div><div><span style="font-family:monospace,monospace;font-size:12.8px">if( $some_value =~ m/\Q${\( $object->foo )}\E/ ) {</span><br></div><div><br></div><div>Is that ${ } "protecting" the $object->foo so that the regex engine doesn't see it as regex-y?</div><div><br></div><div>Best Regards,</div><div>Robert Stone</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Aug 23, 2016 at 2:19 PM, Julian Brown via Houston <span dir="ltr"><<a href="mailto:houston@pm.org" target="_blank">houston@pm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I am not familiar with Moose, but am not convinced this is specific to Moose.<div><br></div><div>I assume $object->foo is really a method call that returns the foo attribute?  Or is it like a hash value?</div><div><br></div><div><div><br></div><div><font face="monospace, monospace">• [root@julian64:~/work]# cat <a href="http://doit.pl" target="_blank">doit.pl</a></font></div><div><font face="monospace, monospace">#!/usr/local/cpanel/3rdparty/<wbr>bin/perl</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">use strict;</font></div><div><font face="monospace, monospace">use warnings;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">my $var = "A";</font></div><div><font face="monospace, monospace">my $var_ref = \$var;</font></div><div><font face="monospace, monospace"><br></font></div><div><font face="monospace, monospace">print "VAR :${var}:\n";</font></div><div><font face="monospace, monospace">print "VAR VAR :${$var_ref}:\n";</font></div></div><div><br></div><div>Output is:</div><div><br></div><div><div>VAR :A:</div><div>VAR VAR :A:</div></div><div><br></div><div>I think we are in the same realm perhaps the parens inside the ${} is necessary to execute the method?</div><div><br></div><div>Julian</div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, Aug 23, 2016 at 2:02 PM, Robert Stone via Houston <span dir="ltr"><<a href="mailto:houston@pm.org" target="_blank">houston@pm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><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/per<wbr>lre.html#Regular-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>
<br></div></div>______________________________<wbr>_________________<br>
Houston mailing list<br>
<a href="mailto:Houston@pm.org" target="_blank">Houston@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/houston" rel="noreferrer" target="_blank">http://mail.pm.org/mailman/lis<wbr>tinfo/houston</a><br>
Website: <a href="http://houston.pm.org/" rel="noreferrer" target="_blank">http://houston.pm.org/</a><br></blockquote></div><br></div>
<br>______________________________<wbr>_________________<br>
Houston mailing list<br>
<a href="mailto:Houston@pm.org">Houston@pm.org</a><br>
<a href="http://mail.pm.org/mailman/listinfo/houston" rel="noreferrer" target="_blank">http://mail.pm.org/mailman/<wbr>listinfo/houston</a><br>
Website: <a href="http://houston.pm.org/" rel="noreferrer" target="_blank">http://houston.pm.org/</a><br></blockquote></div><br></div>