in reply to Re^2: understanding closures
in thread understanding closures
reasonablekeith,
Here is a clue - what happens when you forget about closures and run the following code?
Here is a clue - what happens when you forget about closures and run the following code?
The ++ operator (see perlop) first retrieves the current value and then increments the value when used as post-increment.#!/usr/bin/perl use strict; use warnings; my $cnt = 0; print $cnt++, "\n"; print $cnt++, "\n"; print $cnt += 10, "\n"; print $cnt++, "\n"; print $cnt++, "\n";
- Start at 0
- Return 0, make $cnt 1
- Return 1, make $cnt 2
- Return 2 + 10, make $cnt 12
- Return 12, make $cnt 13
- Return 13, make $cnt 14
Cheers - L~R
In Section
Seekers of Perl Wisdom