in reply to Listglob

You can roll your own thusly:

my @param = qw( *.txt *.p? ); print "$_\n" for find( \@param, 'c:/' ); sub find { my ($finds, $dir) = @_; $dir ||= './'; # defult to CWD if no dir supplied opendir D, $dir or die "Can't read $dir $!"; my @file_list = grep { ! -d $dir.$_ and ! -l $dir.$_ }readdir D; closedir D; my @terms; # modify * to .* and ? to . and quotemeta rest so regex friendly for my $term (@$finds) { $term = quotemeta $term; $term =~ s/\\\*/.*/g; $term =~ s/\\\?/./g; push @terms, $term; } # build regex my $re = '(?:' . (join "|", @terms) . ')'; $re = qr/$re/; return grep { /^$re\z/s } @file_list; }

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Replies are listed 'Best First'.
•Re: Re: Listglob
by merlyn (Sage) on Apr 17, 2002 at 18:40 UTC
    Doesn't work if the pattern is foo*/*bar, since you are doing only one readdir. As others have said in this thread already, why reinvent the glob built-in?

    -- Randal L. Schwartz, Perl hacker

      Don't shout, you're hurting my eyes. As for why. Why not? Do you always drive just because it's faster? Would you not climb Everest because other have before you? Do you refuse to breath because others have been there, done that? Give the don't reinvent the wheel bit a break.

      cheers

      tachyon

        While climbing Everest is certainly interesting in a hard core life experience sort of way, it's rarely good advice on the best way to get from point a to point b.

        (For the record, I appreciate both your post and merlyn's reply. It's interesting to see how it can be done, but seekers of wisdom need to understand how dangerous a path it can be.)

        ()-()
         \"/
          `                                                   ` 
        
        Give the don't reinvent the wheel bit a break.
        I would, if you would make clear that you're inventing an inferior wheel than what is already readily available.

        I know I've made that point here before.

        I don't mind people experimenting in the privacy of their own cube. Or even post it here as a request for comment and feedback.

        But when they post it here as a solution, without disclosing that it is inferior to an existing solution, I believe it is necessary for it to be properly annotated as such by those who know. It's not personal: it's to prevent harm coming to others who cannot distinguish the real thing from a failed imitation.

        -- Randal L. Schwartz, Perl hacker