On Mon, 2005-03-07 at 11:36, Ronald J Kimball wrote:
> >     $y = $x++ + 1;
> > 
> > is quite readable, and very clear in its intent if you know know what
> > "postfix:++" and "infix:+" do (and you'd better). You don't even have to
> > know precedence, as it is implied by the (now correct) use of
> > whitespace.
> 
> It's fairly readable (which is subjective anyway), but I don't think it is
> clear in its intent.  Since it is equivalent to C<< $y = ++$x >> when $x is
> a number, I would be unsure why the programmer wrote it in the more
> complicated way.  Did they really mean to do that, or were they trying to
> do something different and erred?

I would assume that there's a reason that they're not equivalent in this
specific context, but yes you're right in the general case they are the
same. Some people would not realize that right off the bat, though and
might just use this version as it's the first that comes to mind for
them.

As for not being the same... here's one example:

        $ perl -le '$x=1/3;{use int; $y=$x+++1}print $y'
        1
        $ perl -le '$x=1/3;{use int; $y=++$x}print $y'
        1.33333333333333

Enjoy.


 
_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to