Hi All, 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. I started reading following manual : *https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>* I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here. There is following info at manual: *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.* It is clear for following example *get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see But next example is as follow: *get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?* Next example is stranger *:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};* Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- * *Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00*
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? Daniel On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli@gmail.com> wrote:
Hi All,
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.
I started reading following manual :
*https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>*
I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here.
There is following info at manual:
*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.* It is clear for following example
*get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see
But next example is as follow:
*get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?*
Next example is stranger
*:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};*
Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- *
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
Hi Kadir For test3 I think you were expecting the behaviour of this code get '/test3/:name' => sub { "Hello there, " . (defined param('name') ? param('name') : "whoever you are!"); }; but you were getting the behaviour of this code get '/test3/:name' => sub { ("Hello there, " . defined param('name')) ? param('name') : "whoever you are!"; }; The reason for this is that '.' has higher operator precedence than '?:' http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity Hope that helps! Andrew On Fri, Apr 3, 2015 at 6:59 PM, D Perrett <perrettdl@googlemail.com> wrote:
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?
Daniel On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli@gmail.com> wrote:
Hi All,
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.
I started reading following manual :
*https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>*
I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here.
There is following info at manual:
*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.* It is clear for following example
*get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see
But next example is as follow:
*get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?*
Next example is stranger
*:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};*
Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- *
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Andrew Solomon Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
Hi Perrett && Andrew, Thanks for your reply, @Perrett, *In perl, the value of the last statement executed in a code block is it's return value* I surprised very much. At following code, I thought it would print '3', but it writes '4' which means that you are right. *my $var = '3';$var = &test; print $var; # prints 3 not 4 although there is no return at sub test sub test { "4";}* Althouh I worked with Perl CGI for 7 years I realized now, this is bad for me! Until today, I always wrote 'return 4' for following example thinking that Perl behaves lile C code @Andrew You are right too. But I did not realize that there is '.' instead of '?' But I think most people reading manual may not realize this because code is from manual so if it was written by mistake, I think it should be corrected *get '/hello/:name?' => sub {* * "Hello there, " . defined param('name')* * ? param('name')* * : "whoever you are!";* *};* On Fri, Apr 3, 2015 at 9:11 PM, Andrew Solomon <andrew@geekuni.com> wrote:
Hi Kadir
For test3 I think you were expecting the behaviour of this code
get '/test3/:name' => sub { "Hello there, " . (defined param('name') ? param('name') : "whoever you are!"); };
but you were getting the behaviour of this code
get '/test3/:name' => sub { ("Hello there, " . defined param('name')) ? param('name') : "whoever you are!"; };
The reason for this is that '.' has higher operator precedence than '?:'
http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
Hope that helps!
Andrew
On Fri, Apr 3, 2015 at 6:59 PM, D Perrett <perrettdl@googlemail.com> wrote:
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?
Daniel On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli@gmail.com> wrote:
Hi All,
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.
I started reading following manual :
*https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>*
I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here.
There is following info at manual:
*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.* It is clear for following example
*get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see
But next example is as follow:
*get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?*
Next example is stranger
*:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};*
Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- *
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Andrew Solomon
Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- *Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00*
Hi Perret, I wrote wrong *my $var = '3';$var = &test; print $var; # prints '4' not '3' although there is no return at sub test, which means that you are right sub test { "4";}* On Sat, Apr 4, 2015 at 12:29 AM, Kadir Beyazlı <kadirbeyazli@gmail.com> wrote:
Hi Perrett && Andrew,
Thanks for your reply,
@Perrett,
*In perl, the value of the last statement executed in a code block is it's return value*
I surprised very much. At following code, I thought it would print '3', but it writes '4' which means that you are right.
*my $var = '3';$var = &test; print $var; # prints 3 not 4 although there is no return at sub test sub test { "4";}* Althouh I worked with Perl CGI for 7 years I realized now, this is bad for me! Until today, I always wrote 'return 4' for following example thinking that Perl behaves lile C code
@Andrew
You are right too. But I did not realize that there is '.' instead of '?'
But I think most people reading manual may not realize this because code is from manual so if it was written by mistake, I think it should be corrected
*get '/hello/:name?' => sub {* * "Hello there, " . defined param('name')* * ? param('name')* * : "whoever you are!";* *};*
On Fri, Apr 3, 2015 at 9:11 PM, Andrew Solomon <andrew@geekuni.com> wrote:
Hi Kadir
For test3 I think you were expecting the behaviour of this code
get '/test3/:name' => sub { "Hello there, " . (defined param('name') ? param('name') : "whoever you are!"); };
but you were getting the behaviour of this code
get '/test3/:name' => sub { ("Hello there, " . defined param('name')) ? param('name') : "whoever you are!"; };
The reason for this is that '.' has higher operator precedence than '?:'
http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
Hope that helps!
Andrew
On Fri, Apr 3, 2015 at 6:59 PM, D Perrett <perrettdl@googlemail.com> wrote:
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?
Daniel On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli@gmail.com> wrote:
Hi All,
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.
I started reading following manual :
*https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>*
I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here.
There is following info at manual:
*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.* It is clear for following example
*get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see
But next example is as follow:
*get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?*
Next example is stranger
*:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};*
Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- *
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Andrew Solomon
Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
--
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
-- *Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00*
Thanks for pointing out the error Kadir! The fix should be in the next release: https://github.com/PerlDancer/Dancer2/pull/878 cheers Andrew On Fri, Apr 3, 2015 at 10:29 PM, Kadir Beyazlı <kadirbeyazli@gmail.com> wrote:
Hi Perrett && Andrew,
Thanks for your reply,
@Perrett,
*In perl, the value of the last statement executed in a code block is it's return value*
I surprised very much. At following code, I thought it would print '3', but it writes '4' which means that you are right.
*my $var = '3';$var = &test; print $var; # prints 3 not 4 although there is no return at sub test sub test { "4";}* Althouh I worked with Perl CGI for 7 years I realized now, this is bad for me! Until today, I always wrote 'return 4' for following example thinking that Perl behaves lile C code
@Andrew
You are right too. But I did not realize that there is '.' instead of '?'
But I think most people reading manual may not realize this because code is from manual so if it was written by mistake, I think it should be corrected
*get '/hello/:name?' => sub {* * "Hello there, " . defined param('name')* * ? param('name')* * : "whoever you are!";* *};*
On Fri, Apr 3, 2015 at 9:11 PM, Andrew Solomon <andrew@geekuni.com> wrote:
Hi Kadir
For test3 I think you were expecting the behaviour of this code
get '/test3/:name' => sub { "Hello there, " . (defined param('name') ? param('name') : "whoever you are!"); };
but you were getting the behaviour of this code
get '/test3/:name' => sub { ("Hello there, " . defined param('name')) ? param('name') : "whoever you are!"; };
The reason for this is that '.' has higher operator precedence than '?:'
http://perldoc.perl.org/perlop.html#Operator-Precedence-and-Associativity
Hope that helps!
Andrew
On Fri, Apr 3, 2015 at 6:59 PM, D Perrett <perrettdl@googlemail.com> wrote:
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?
Daniel On 3 Apr 2015 18:30, "Kadir Beyazlı" <kadirbeyazli@gmail.com> wrote:
Hi All,
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.
I started reading following manual :
*https://metacpan.org/pod/Dancer2::Manual <https://metacpan.org/pod/Dancer2::Manual>*
I installed Dancer2, placked up it and opened web page from localhost. Everything is OK until here.
There is following info at manual:
*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.* It is clear for following example
*get '/test1/:name' => sub { return "Hi there " . params->{name};};* because it returns a string and when I write *http://localhost:5000/test1/kadir <http://localhost:5000/test1/kadir> *to browser I see *Hi there kadir* which is the string I expect to see
But next example is as follow:
*get '/test2/:name' => sub { "Hey ".param('name').", welcome here!";};* It does not return anything. Because there is no *return* keyword *.* Despite this I see *Hi there kadir *when I write *http://localhost:5000/test2/kadir <http://localhost:5000/test2/kadir>* But above red background colored sentence says that it must return a value *?*
Next example is stranger
*:get '/test3/:name' => sub { "Hello there, " . defined param('name') ? param('name') : "whoever you are!";};*
Again there is no *return* keyword. When I write *http://localhost:5000/test3/kadir <http://localhost:5000/test3/kadir> *I see only kadir. But at test2 example, I saw all words despite there is no return keyword. So what is rule? *-- *
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Andrew Solomon
Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
--
*Kadir BeyazlıComputer Engineer* *GSM : +90 535 821 50 00 <%2B90%20535%20821%2050%2000>*
_______________________________________________ dancer-users mailing list dancer-users@dancer.pm http://lists.preshweb.co.uk/mailman/listinfo/dancer-users
-- Andrew Solomon Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon
participants (3)
-
Andrew Solomon -
D Perrett -
Kadir Beyazlı