<div dir="ltr">Hi Kadir<div><br></div><div>For test3 I think you were expecting the behaviour of this code</div><div><br></div><div><div>get '/test3/:name' => sub {</div><div>    "Hello there, " .</div><div>    (defined param('name') ? param('name') : "whoever you are!");</div><div>};</div><div><br></div><div>but you were getting the behaviour of this code</div><div><br></div><div>get '/test3/:name' => sub {</div><div>    ("Hello there, " .  defined param('name')) ?</div><div>      param('name') : "whoever you are!";</div><div>};</div><div><br></div></div><div>The reason for this is that '.' has higher operator precedence than '?:'</div><div><br></div><div><a href="http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity">http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity</a><br></div><div><br></div><div>Hope that helps!</div><div><br></div><div>Andrew</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 3, 2015 at 6:59 PM, D Perrett <span dir="ltr"><<a href="mailto:perrettdl@googlemail.com" target="_blank">perrettdl@googlemail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">In perl, the value of the last statement executed in a code block is it's return value, an explicit return is only needed if you want to exit the chose block earlier than the last statement. Not sure why your third example isn't working for you. Have you restarted your dancer server since you edited the code?</p>
<p dir="ltr">Daniel</p>
<div class="gmail_quote"><div><div class="h5">On 3 Apr 2015 18:30, "Kadir Beyazlı" <<a href="mailto:kadirbeyazli@gmail.com" target="_blank">kadirbeyazli@gmail.com</a>> wrote:<br type="attribution"></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"><div><div>Hi All,<br><br></div>I am novice at Dancer, I am sure my question is very easy for you but I decided to ask because I failed at the beginning of my study.<br><br></div>I started reading following manual :<br clear="all"><div><div><div><br><i><a href="https://metacpan.org/pod/Dancer2::Manual" target="_blank">https://metacpan.org/pod/Dancer2::Manual</a></i><br><br></div><div>I installed Dancer2, placked up it and opened web page from localhost.<br></div><div>Everything is OK until here.<br><br></div><div>There is following info at manual:<i><br></i><p><span style="background-color:rgb(255,255,0)"><i>The code block given to the route handler has to return a string which will be used as the content to render to the client.</i></span></p>It is clear for following example <br><br><i>get '/test1/:name' => sub {<br>    return "Hi there " . params->{name};<br>};<br></i><br>because it returns a string and when I write <i><a href="http://localhost:5000/test1/kadir" target="_blank">http://localhost:5000/test1/kadir</a> </i>to browser I see  <i>Hi there kadir</i> which is the string I expect to see<br><br></div><div>But next example is as follow:<br><br><i>get '/test2/:name' => sub {<br>    "Hey ".param('name').", welcome here!";<br>};<br><br></i></div><div>It does not return anything. Because there is no <i>return</i> keyword<i>.<br></i></div><div>Despite this I see   <i>Hi there kadir  </i>when I write <i><a href="http://localhost:5000/test2/kadir" target="_blank">http://localhost:5000/test2/kadir</a><br></i></div><div>But above red background colored sentence says that it must return a value<i>?<br></i></div><div><i><br></i></div><div>Next example is stranger<i>:<br><br>get '/test3/:name' => sub {<br>    "Hello there, " . defined param('name')<br>                    ? param('name')<br>                    : "whoever you are!";<br>};</i><i><br></i></div><div><i><br></i></div><div>Again there is no <i>return</i> keyword. When I write  <i><a href="http://localhost:5000/test3/kadir" target="_blank">http://localhost:5000/test3/kadir</a> </i>I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule?<i><br></i></div><div><i>-- </i><br><div><div dir="ltr"><div><b><i>Kadir Beyazlı<br>Computer Engineer</i></b></div><div><b><i>GSM : <a href="tel:%2B90%20535%20821%2050%2000" value="+905358215000" target="_blank">+90 535 821 50 00</a></i></b><br></div></div></div>
</div></div></div></div>
<br></div></div>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm" target="_blank">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div>
<br>_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">Andrew Solomon<div><br></div><div>Mentor@Geekuni <a href="http://geekuni.com/" target="_blank">http://geekuni.com/</a></div><div><a href="http://www.linkedin.com/in/asolomon" target="_blank">http://www.linkedin.com/in/asolomon</a><br></div></div></div>
</div>