Iterators.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi.

OK. I'm stuck. I just can't work this out.

I like SPL. I like the re-usability. It seems right. But I just can't
work it out.

I want to read through a file system, looking for files of a particular type.
I want to ignore and not traverse any folder with a specific name
anywhere in the directory tree.
I want to examine the contents of the file with a set of regular
expressions and call a closure for each match for each regex which
will replace and replace the file with the amended one.
I want to get a list of the files altered along with which regex and
the number of changes.

The part I'm really stuck on is working out what elements of the SPL
fit my issue the best and what bits I have to implement myself, with
regard to the file system iteration and filtering.

The tree is pretty large - just over 5,000 files with 5,700
directories. The deepest file is 12 levels down.


Now I know someone could supply a solution not using the SPL. I've got
one of those. But trying to use the SPL just seems to awkward. Too
many choices. Too many things with the same name

Iterator, RecursiveIterator, RecusiverIteratorIterator.

An Iterator suggests that it can work on a simple array ($argv for
example). A non SPL variant would be foreach().
A RecursiveIterator suggests it can iterator recursively on nested
data (a file system for example). Using a function which uses
scandir() and calls itself for a directory would look like a recursive
iterator.

So what does a RecursiveIteratorIterator do? Documentation says "Can
be used to iterate through recursive iterators.".

But that sounds daft. The RecursiveIterator is the handling the
parent/child/tree navigation (isn't it - if not why not?)


The name really doesn't help me to understand what's going on or what its for.


Is there any place that can describe the SPL in a different way.

I know it's probably just me, but it really seems like I'm only just
scratching the surface. And not really getting anywhere.


-- 
Richard Quadling
Twitter : EE : Zend
@RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux