Erik Price <[EMAIL PROTECTED]> writes:

| Man!  And I thought one of the nice things about Perl was you didn't
| have to use an Iterator to traverse a List!
| 
| Iterator it = myList.iterator();
| while (it.hasNext()) {
|       MyObject mo = (MyObject)it.next();
|       // do something with mo
| }
| 
| (In all honesty, I really do think [Java/Python-style] iterators are
| cool, for situations that need them.  But it's admittedly more work
| than using a counter variable, so when you want to bang out some quick
| Perl, it's nice not to have to bother with it.)

In Python, the iterator construction and traversal are automatically
performed for you when you use for...in, so the following works:

  for mo in myList:
      # do something with mo

provided that myList's class defines an __iter__ method that returns
an iterator object, and that that iterator defines a next() method.

-- 
http://www.dfan.org


_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to