in reply to Filename Template

Has anyone any direction to point me in?

Sure, File::Find::Rule

Replies are listed 'Best First'.
Re: Re: Filename Template
by broquaint (Abbot) on Aug 07, 2003 at 15:00 UTC
    Further to that ...
    use File::Find::Rule; my $template = 'aaaa-nnnnnnnn'; (my $regex = $template) =~ s/([an])/$1 eq 'a' ? '[a-z]' : '[0-9]'/eig; my $matcher = rule( file => maxdepth => 1, name => qr/^$regex/i, start => $ARGV[0] ); while(my $file = $matcher->match) { ... }
    See. the File::Find::Rule docs for more info.
    HTH

    _________
    broquaint

Re: Re: Filename Template
by Limbic~Region (Chancellor) on Aug 07, 2003 at 15:06 UTC
    Abstraction,
    To expound on what you have said:
    #!/usr/bin/perl -w use strict; use File::Find::Rule; my @files = File::Find::Rule->file() ->name( qr/^[a-zA-Z]{4}-\d{8}/ ) ->in( / );
    It appeared at first in the docs that all you could do was file globs, but later on I saw a regex, so I think this will work.

    Cheers - L~R

    Update: Bah, broquaint beat me to it, so yes it will work. What's worse - his solution provides the ability to modify the template without modifying the regex. I guess the only thing I would have done differently is changed the character class to [a-zA-Z] instead of using /i for speed reasons - but if it runs a tad bit slower it just means you can go get more caffeine.

      even a simple readdir should do the trick

      #!/usr/bin/perl -w use strict; my $dir = '/some/dir'; my $file_re = qr/^(?:\.+|[a-zA-Z]{4}-[0-9]{8})$/; opendir(DIR, $dir) or die "opening $dir: $!\n"; for ( grep(!/$file_re/, readdir(DIR)) ) { # deal with non conforming file names here } closedir(DIR);

      use perl;