Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^3: understanding closures

by Limbic~Region (Chancellor)
on Sep 23, 2005 at 14:04 UTC ( #494537=note: print w/replies, xml ) Need Help??


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?
#!/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";
The ++ operator (see perlop) first retrieves the current value and then increments the value when used as post-increment.
  • 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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://494537]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-04-21 08:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?