FAQ
Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

2014-06-23 11:16:32 Mon $ svn diff t/lib/Apache2/TestReload.pm
Index: t/lib/Apache2/TestReload.pm
===================================================================
--- t/lib/Apache2/TestReload.pm (revision 1604706)
+++ t/lib/Apache2/TestReload.pm (working copy)
@@ -15,7 +15,8 @@
sub handler {
      my $r = shift;
      $pass++;
- if ($r->args eq 'last') {
+ my $args = $r->args;
+ if (defined $args && $r->args eq 'last') {
          Apache2::Reload->unregister_module($package);
          ModPerl::Util::unload_package($package);
          $pass = 0;

Also reported on Apache::Reload at rt.cpan.org.

Thanks.

Mark

Search Discussions

  • Joshua Narins at Jun 26, 2014 at 8:04 am

    On Mon, Jun 23, 2014 at 06:21:37PM +0000, Mark Hedges wrote:
    Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

    2014-06-23 11:16:32 Mon $ svn diff t/lib/Apache2/TestReload.pm
    Index: t/lib/Apache2/TestReload.pm
    ===================================================================
    --- t/lib/Apache2/TestReload.pm (revision 1604706)
    +++ t/lib/Apache2/TestReload.pm (working copy)
    @@ -15,7 +15,8 @@
    sub handler {
    my $r = shift;
    $pass++;
    - if ($r->args eq 'last') {
    + my $args = $r->args;
    + if (defined $args && $r->args eq 'last') {
    Apache2::Reload->unregister_module($package);
    ModPerl::Util::unload_package($package);
    $pass = 0;
    Why not just

    my $args = $r->args;
    if (defined $args and $args eq 'last') {

    I guess repeat calls to $r->args have virtually no cost?
  • Joshua Narins at Jun 26, 2014 at 4:13 pm

    On Thu, Jun 26, 2014 at 03:52:33AM -0400, Joshua Narins wrote:
    On Mon, Jun 23, 2014 at 06:21:37PM +0000, Mark Hedges wrote:
    Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

    2014-06-23 11:16:32 Mon $ svn diff t/lib/Apache2/TestReload.pm
    Index: t/lib/Apache2/TestReload.pm
    ===================================================================
    --- t/lib/Apache2/TestReload.pm (revision 1604706)
    +++ t/lib/Apache2/TestReload.pm (working copy)
    @@ -15,7 +15,8 @@
    sub handler {
    my $r = shift;
    $pass++;
    - if ($r->args eq 'last') {
    + my $args = $r->args;
    + if (defined $args && $r->args eq 'last') {
    Apache2::Reload->unregister_module($package);
    ModPerl::Util::unload_package($package);
    $pass = 0;
    Why not just

    my $args = $r->args;
    if (defined $args and $args eq 'last') {

    I guess repeat calls to $r->args have virtually no cost?
    I am sorry. I am not competent to help with the big stuff in mod_perl, so
    I just nip around the fringes like an annoying dog.
    Also reported on Apache::Reload at rt.cpan.org.

    Thanks.

    Mark
  • Sergiy Borodych at Jun 26, 2014 at 4:13 pm
    Hello,

    another question:
      why not just

    my $args = $r->args;
    if ( $args and $args eq 'last' ) {

    (without defined)

    or even

      if ( my $args = $r->args and $args eq 'last' ) {

    :)


    2014-06-26 10:52 GMT+03:00 Joshua Narins <josh@mobehr.net>:
    On Mon, Jun 23, 2014 at 06:21:37PM +0000, Mark Hedges wrote:
    Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

    2014-06-23 11:16:32 Mon $ svn diff t/lib/Apache2/TestReload.pm
    Index: t/lib/Apache2/TestReload.pm
    ===================================================================
    --- t/lib/Apache2/TestReload.pm (revision 1604706)
    +++ t/lib/Apache2/TestReload.pm (working copy)
    @@ -15,7 +15,8 @@
    sub handler {
    my $r = shift;
    $pass++;
    - if ($r->args eq 'last') {
    + my $args = $r->args;
    + if (defined $args && $r->args eq 'last') {
    Apache2::Reload->unregister_module($package);
    ModPerl::Util::unload_package($package);
    $pass = 0;
    Why not just

    my $args = $r->args;
    if (defined $args and $args eq 'last') {

    I guess repeat calls to $r->args have virtually no cost?

    --
    Sergiy Borodych
    http://bor.org.ua
  • Mark Hedges at Jun 26, 2014 at 5:16 pm
    Nope Joshua you're right, I missed that.

    defined() is faster than the logical check because the logical check checks defined, then checks if empty string, then checks if numerically 0, except if it is 0E0 (zero but true). One operation versus the same operation plus three more; the one by itself is certainly less computation.

    However I'm not sure about the last one. That is a cool idea. We'd have to benchmark it. :-)

    Also is '&&' faster than 'and'?

    Mark



    From: sergiy.borodych@gmail.com On Behalf Of Sergiy Borodych
    Sent: Thursday, June 26, 2014 2:14 AM
    To: Joshua Narins
    Cc: Mark Hedges; modperl@perl.apache.org
    Subject: Re: bug in trunk in Apache::Reload test

    Hello,
    another question:
     why not just

    my $args = $r->args;
    if ( $args and $args eq 'last' ) {

    (without defined)

    or even

     if ( my $args = $r->args and $args eq 'last' ) {

    :)

    2014-06-26 10:52 GMT+03:00 Joshua Narins <josh@mobehr.net>:
    On Mon, Jun 23, 2014 at 06:21:37PM +0000, Mark Hedges wrote:
    Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

    2014-06-23 11:16:32 Mon  $ svn diff t/lib/Apache2/TestReload.pm
    Index: t/lib/Apache2/TestReload.pm
    ===================================================================
    --- t/lib/Apache2/TestReload.pm             (revision 1604706)
    +++ t/lib/Apache2/TestReload.pm          (working copy)
    @@ -15,7 +15,8 @@
    sub handler {
    my $r = shift;
    $pass++;
    -    if ($r->args eq 'last') {
    +    my $args = $r->args;
    +    if (defined $args && $r->args eq 'last') {
    Apache2::Reload->unregister_module($package);
    ModPerl::Util::unload_package($package);
    $pass = 0;
    Why not just

    my $args = $r->args;
    if (defined $args and $args eq 'last') {

    I guess repeat calls to $r->args have virtually no cost?



    --
    Sergiy Borodych
    http://bor.org.ua
  • André Warnier at Jun 26, 2014 at 6:51 pm
    There is also something to be said for writing clear and obvious code, even if it does
    cost a couple of CPU cycles of which there are about 2.5 billion available every second.

    I prefer this version :

    my $args = $r->args;
    if (defined($args) && ($args eq 'last')) {
    ...
    }

    unless $args is used exclusively inside the if {} block (*).
    Clear, no side-effects, no hidden meaning behind the "if ($args)", no double dereferencing
    overhead - assuming perl doesn't optimise this itself - , no worries about operator
    precedence etc.
    Syntactic sugar and perl virtuosity are nice if they are for one's self-satisfaction,
    hubris and laziness, but if some junior has to handle this code after you lose interest,
    it's better to be plain and obvious.

    (*) in which case I might just about forgive you for writing
    if (defined(my $args = $r->args) && ($args eq 'last')) {
    , although that would probably force the junior to consult the (otherwise excellent and
    humorous) perl documentation to verify the scope of $args.

    Mark Hedges wrote:
    Nope Joshua you're right, I missed that.

    defined() is faster than the logical check because the logical check checks defined, then checks if empty string, then checks if numerically 0, except if it is 0E0 (zero but true). One operation versus the same operation plus three more; the one by itself is certainly less computation.

    However I'm not sure about the last one. That is a cool idea. We'd have to benchmark it. :-)

    Also is '&&' faster than 'and'?

    Mark



    From: sergiy.borodych@gmail.com On Behalf Of Sergiy Borodych
    Sent: Thursday, June 26, 2014 2:14 AM
    To: Joshua Narins
    Cc: Mark Hedges; modperl@perl.apache.org
    Subject: Re: bug in trunk in Apache::Reload test

    Hello,
    another question:
    why not just

    my $args = $r->args;
    if ( $args and $args eq 'last' ) {

    (without defined)

    or even

    if ( my $args = $r->args and $args eq 'last' ) {

    :)

    2014-06-26 10:52 GMT+03:00 Joshua Narins <josh@mobehr.net>:
    On Mon, Jun 23, 2014 at 06:21:37PM +0000, Mark Hedges wrote:
    Perl 5.20.0, Apache 2.2.27, APR 1.5.1, APR-util 1.5.3, mod_perl trunk.

    2014-06-23 11:16:32 Mon $ svn diff t/lib/Apache2/TestReload.pm
    Index: t/lib/Apache2/TestReload.pm
    ===================================================================
    --- t/lib/Apache2/TestReload.pm (revision 1604706)
    +++ t/lib/Apache2/TestReload.pm (working copy)
    @@ -15,7 +15,8 @@
    sub handler {
    my $r = shift;
    $pass++;
    - if ($r->args eq 'last') {
    + my $args = $r->args;
    + if (defined $args && $r->args eq 'last') {
    Apache2::Reload->unregister_module($package);
    ModPerl::Util::unload_package($package);
    $pass = 0;
    Why not just

    my $args = $r->args;
    if (defined $args and $args eq 'last') {

    I guess repeat calls to $r->args have virtually no cost?

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupmodperl @
categoriesmodperl, perl
postedJun 23, '14 at 6:22p
activeJun 26, '14 at 6:51p
posts6
users4
websiteperl.apache.org

People

Translate

site design / logo © 2018 Grokbase