The Perldoc here says
Unary "+" has no effect whatsoever, even on strings. It is useful syntactically for separating a function name from a parenthesized expression that would otherwise be interpreted as the complete list of function arguments.
and to illustrate this I did this
use warnings;
use strict;
my $return=&call();
print "Return value :$return";
sub innercall($)
{
print "I am called\n";
return 'gzip';
}
sub call()
{
return +(innercall('test')||'') =~ /gzip/;
}
The call
return +(innercall('test')||'') =~ /gzip/;
and
return (innercall('test')||'') =~ /gzip/;
exhibit same behavior!Hope this helps!!
PS:Just in case you are not aware, the line
return +($r->header_in('Accept-Encoding')||'') =~ /gzip/;
would return either a '1' or ' ' depending on the match success and failure respectively
The world is so big for any individual to conquer
| [reply] [Watch: Dir/Any] [d/l] [select] |
In other contexts (which the use of NaN (not-a-number) suggests), +0 is a number. If it is defined in IEEE754 floating point arithmetic. (There is a -0 too).
So 10 / +0 is "positive infinity" and 10 / -0 is "negative infinity".
See http://en.wikipedia.org/wiki/Division_by_zero#Division_by_zero_in_computer_arithmetic for more gory details.
But - as others have noted - this probably does nothing in perl. (Although - can you overload unary plus? If so, someone might be doing something Too Clever.) | [reply] [Watch: Dir/Any] |
There is a -0 too
Signed zeroes exist in the mpfr library - and are therefore accessible to perl via Math::MPFR:
C:\_32>perl -MMath::MPFR -e "$z=Math::MPFR->new(0);$z/=-1;print $z"
-0
They don't seem to be accessible via either Math::Pari or Math::BigFloat
C:\_32>perl -MMath::Pari -e "$x=PARI(0);$x/=-1;print $x"
0
C:\_32>perl -MMath::BigFloat -e "$z=Math::BigFloat->new(0);$z/=-1;prin
+t $z"
0
can you overload unary plus?
I don't think so. Even if you could, returning '+0' would not use the overloaded '+' subroutine - overloading works only with blessed objects (and 0 is not a blessed object :-)
Cheers, Rob | [reply] [Watch: Dir/Any] [d/l] [select] |
| [reply] [Watch: Dir/Any] |
if (!defined($how_decide) || lc($how_decide) eq 'header') {
return +($r->header_in('Accept-Encoding')||'') =~ /gzip/;
} elsif (lc($how_decide) eq 'user-agent') {
updated: Removed the duplicate "found" word in my comment. | [reply] [Watch: Dir/Any] [d/l] |
In that example the + tells perl that the parens are not enclosing the arguments to a function call, so it is parsed correctly.
| [reply] [Watch: Dir/Any] [d/l] |
I belive '+' has some importance.
For me, return values of +0, -0, and 0 are indistinguishable from each other - which means that the '+' has no significance at all:
C:\_32>perl -MDevel::Peek -e "Dump(+0)"
SV = IV(0x1fe2d28) at 0x343cbc
REFCNT = 1
FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
IV = 0
C:\_32>perl -MDevel::Peek -e "Dump(-0)"
SV = IV(0x432d2c) at 0xd73cec
REFCNT = 1
FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
IV = 0
C:\_32>perl -MDevel::Peek -e "Dump(0)"
SV = IV(0x2492d28) at 0x23cbc
REFCNT = 1
FLAGS = (PADBUSY,PADTMP,IOK,READONLY,pIOK)
IV = 0
(Replace the double quotes with single quotes if you're on a *nix-type operating system.)
Cheers, Rob | [reply] [Watch: Dir/Any] [d/l] |