develooper Front page | perl.perl5.porters | Postings from March 2000

Re: What's left to do? [LONG]

Thread Previous | Thread Next
Tom Christiansen
March 22, 2000 18:54
Re: What's left to do? [LONG]
Message ID:
>I wrote:
>> # Make File::Find export C<$name> etc manually
>> Ten or fifteen minutes work for someone with the motivation,
>> I'd think.

>Or less:

>-@EXPORT = qw(find finddepth);
>+@EXPORT = qw(find finddepth $dir $name $fullname);

No, no, no, no.  A thousand times no.  You can't *do* that.  Morality
matters aside, it simply Does Not Work!   We've been through this
a good three times before.  The collective memory is mournfully short.


    #!/usr/bin/perl -Wl
    use File::Find;

    print "Normal import:";
    *name = \$File::Find::name;
    find sub { print "Found $name" if -d }, @ARGV;

    print "\nExtreme import:";
    *name = *File::Find::name;
    find sub { print "Found $name" if -d }, @ARGV;


    % perl /tmp/findem /var/tmp
    Normal import:
    Use of uninitialized value in concatenation (.) at /tmp/findem line 6.
    Use of uninitialized value in concatenation (.) at /tmp/findem line 6.

    Extreme import:
    Found /var/tmp
    Found /var/tmp/vi.recover

That because this screws you up:

402:        local ($dir, $name, $prune, *DIR);

If you run local() on something that's only partially imported, the
importer does not get access the local copy.  This only happens on
a complete import of the entire stab entry.  This really should be
documented somewhere.  I feel like only three or four of us 
ever remember it.  Or perhaps fewer. :-(

Now, that does mean that 

    @EXPORT = qw(find finddepth *dir *name *fullname);

will work, but I believe it is incredibly nasty to kill somebody's
existing variables (not to mention their functions and handles and
formats) unless they asked you to.  It's one thing to put things
in @EXPORT in the first place, but quite another to put something
there in an existing module people are already using.  This, too,
should be documented somewhere.

So what are you going to do, put those in @EXPORT_OK?  I can just
see folks being told to 

    use File::Find qw/:DEFAULT *name/;

There's really little help for the matter, but I bet they'll be
puzzled by that starry-eyed import, and astonished that there &name
function just mysteriously became &File::Find::name, which does not

Perhaps you should have them pull in some :blah tag, and then give
lots of doc warnings.  Not that anyone ever RsTFM.  Well, that's a
sin that carries its own punishment unfailiningly meted out, now
isn't it? :-)


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About