[Za-pm] Passing values

Nick Cleaton nick at cleaton.net
Mon Feb 9 05:40:16 CST 2004


On Mon, Feb 09, 2004 at 01:16:29PM +0200, Spike wrote:
> Christiaan pointed this out to me:
> 
> Spike - What dont you get right - I put this together and it works?
> 
> It should also work if you stick with: return @results;
> 
> Do you also make provision for the new "09" and "19" 11th and 12th digits?
> 
> If I do ($DoB, $sex) = said(1234567890123) or die("$errstr"); (without ||) 
> everything works
> 
> If I do ($DoB, $sex) = said(1234567890123) || die("$errstr"); (with ||) 
> things go awry
> 
> Why?
> 
> 
> Christiaan
> 
> He is right - when I use '||' it all goes wrong and with 'or' it does 
> exactly what i wanted.
> what is the difference?

Because '||' has a higher precedence than '=', whereas 'or' has a lower
precedence, so 

   ($DoB, $sex) = said(1234567890123) || die("$errstr");

is the same as:

   ($DoB, $sex) = ( said(1234567890123) || die("$errstr") );

and the return value from said() is being ||ed with something else.  Since
|| is a scalar operation, this calls said() in a scalar context, so it
can't return a list.

With 'or' however...

   ($DoB, $sex) = said(1234567890123) or die("$errstr");

is the same as:
   
   ( ($DoB, $sex) = said(1234567890123) ) or die("$errstr");

and the return value from said() is being assigned to a list, so said()
will be called in a list context and it all works nicely.


Nick


-- 
$_=')=*****   http://www.exonetric.com/  Telehouse UK colo   *****19Pi'.
'TDX\@PT****      GBP40/month +VAT 40G BW no setup fee      ****}4KGXC'.
'~6K&2\6@****                                              ****(v';s/(.)
(.*(.).(.))/$2.($1^chr((ord($3)+ord$4)%128))/exsuntil s/Wo.*oo//s;;print



More information about the Za-pm mailing list