[Cascavel-pm] Readdir com foreach/while
Stanislaw Pusep
creaktive em gmail.com
Quarta Abril 11 06:32:53 PDT 2012
foreach my $f (readdir DH) { ... }
seria aproximadamente equivalente a
my @f = readdir DH;
foreach my $f (@f) { ... }
Ou seja, todos os resultados são pré-carregados e depois enumerados.
Mais lento não fica, mas definitivamente consome mais memória.
ABS()
On Wed, Apr 11, 2012 at 09:52, Ednardo Lobo <ednardo em lobo.eti.br> wrote:
> Uma curiosidade que tenho ...
>
> Em termos de processamento e uso de memória, há alguma diferença entre:
>
> foreach my $f (readdir DH) {
> ...
> }
>
> e
>
> while (my $f = readdir DH) {
> ...
> }
>
>
> readdir DIRHANDLE
> Returns the next directory entry for a directory opened by
> "opendir". If used in list context, returns all the rest of
> the entries in the directory. If there are no more entries,
> returns an undefined value in scalar context or a null list in
> list context.
>
>
> Grato,
>
> --
> Ednardo Lobo
>
> www.lobo.eti.br
> ______________________________**_________________
> Cascavel-pm mailing list
> Cascavel-pm em pm.org
> http://mail.pm.org/mailman/**listinfo/cascavel-pm<http://mail.pm.org/mailman/listinfo/cascavel-pm>
>
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://mail.pm.org/pipermail/cascavel-pm/attachments/20120411/d422a9db/attachment.html>
Mais detalhes sobre a lista de discussão Cascavel-pm