11/25/02
Yow! We are having fun now. I think it is usually not a good
idea to do uniary increment with any other procedure unless it
is surrounded by parenthesis or unless your goal is to baffle
the next person who has to look at your code.... hence fwp.(tic)
these will print the same thing (tho difficult to understand):
print "++$y" . "++$y" . "++$y" . "++$y" . "++$y" ,"\n";
print "++$y" , "++$y" , "++$y" , "++$y" , "++$y" ,"\n";
I'm sure there is a good reason Perl behaves this way, but to
me it just seems wrong.
and apparently it doesn't make any difference if it is a
pre or post increment:
print "$y++" . "$y++" . "$y++" . "$y++" . "$y++" ,"\n";
print "$y++" , "$y++" , "$y++" , "$y++" , "$y++" ,"\n";
The best way I can get my head around this trick is to remember
that although most of us don't write it there, there IS an
"understood" parenthesis after the function "print".
print("$y++" , "$y++" , "$y++" , "$y++" , "$y++" , "$y++" ,"\n");
That still doesn't explain
> print ++$y . ++$y . ++$y . ++$y . ++$y . ++$y ,"\n"; # prints 223456 (and
> not 123456!)
But this "fixes" it:
print (($y++) . ($y++) . ($y++) . ($y++) . ($y++));
print "\n";
print (($y++) , ($y++) , ($y++) , ($y++) , ($y++));
Meryll
[EMAIL PROTECTED] wrote:
Hi All,
Following Bart and Jonathan thoughts on the side effects of list
assignment....
$i = 20;
my($x, $y, $z) = ($i++, +$i, $i++);
Here is a good addition to Bart's examples:
my $i = 20;
my ($x, $y, $z) = ($i++, -$i, $i++);
print "$x $y $z\n";>
Understanding the other examples... can you guess what does it prints?
Can anyone explain why these print different output?
my ($x,$y);
print $x++ , ++$x , $x++ ,"\n"; # prints 032
print $y++ . ++$y . $y++ ,"\n"; # prints 022
I was going to suggest that someone that the ++prefix was bugged only over
the "," operator until I saw this:
my ($x,$y);
print ++$x , ++$x , ++$x , ++$x , ++$x , ++$x ,"\n"; # prints 666666
print ++$y . ++$y . ++$y . ++$y . ++$y . ++$y ,"\n"; # prints 223456 (and
not 123456!)
Shouldn't the super-high precedence of ++ prevent there from being any
distinction between the "." and the "," operator?
Alistair
-----------------------------------------------------------------------
Registered Office:
Marks & Spencer p.l.c
Michael House, Baker Street,
London, W1U 8EP
Registered No. 214436 in England and Wales.
Telephone (020) 7935 4422
Facsimile (020) 7487 2670
www.marksandspencer.com
Please note that electronic mail may be monitored.
This e-mail is confidential. If you received it by mistake, please let us know and then delete it from your system; you should not copy, disclose, or distribute its contents to anyone nor act in reliance on this e-mail, as this is prohibited and may be unlawful.
The registered office of Marks and Spencer Financial Services PLC, Marks and Spencer Unit Trust Management Limited, Marks and Spencer Life Assurance Limited and Marks and Spencer Savings and Investments Limited is Kings Meadow, Chester, CH99 9FB.