develooper Front page | perl.perl5.porters | Postings from August 2008

Re: Diamond iteration (was: Fighting the Good Fight against spamdeluge)

From:
Abigail
Date:
August 1, 2008 08:43
Subject:
Re: Diamond iteration (was: Fighting the Good Fight against spamdeluge)
Message ID:
20080801154345.GI29536@almanda
On Fri, Aug 01, 2008 at 09:26:57AM -0600, Tom Christiansen wrote:
> 
> I still yearn for <> to work on DHs opened by opendir, too.
> Never saw why it didn't.

But how would you know whether <HANDLE> operates on a filehandle named
HANDLE, or a dirhandle named HANDLE? Perl allows them to coexist:

    use strict;
    use warnings;

    open HANDLE, "/etc/passwd" or die;
    opendir HANDLE, "/etc" or die;
    while (<HANDLE>) {print}        # Prints the content of /etc/passwd
    say while $_ = readdir HANDLE;  # Prints the files in /etc


If <HANDLE> operated on dirhandles as well, it wouldn't be clear what
the penultimate line would do.


Abigail



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About