David Moreno Garza am Sonntag, 21. Januar 2007 07:50:
> On Sat, 2007-01-20 at 09:31 +1100, Ken Foskey wrote:
> > > What's exactly the difference between:
> > > ++$lines and $lines++; ?
> >
> > Nothing in this context.
>
> What about other contexts?
Hi David
#!/usr/bin/perl
use strict;
use warnings;
{ # preincrement
my (%h, $i);
$h{++$i}='hi';
print keys %h, ", $i\n";
}
{ # postincrement
my (%h, $i);
$h{$i++}='hi';
print keys %h, ", $i\n";
}
__END__
1, 1
0, 1
The difference is the order of "read current value" (used as hash key value)
and "increment current value" (done by ++ operator).
There's no difference between "standalone" ++$lines and $lines++ because only
increment takes place, and the result value is not used in the same
expression.
See also perldoc perlop, "Auto-increment and Auto-decrement".
Hope this helps!
Dani
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/