in reply to Perl Scripting for testing

This is a case for a perl regular expression. It should look something like this,

my $re = qr/^[A-Z][^_]*_[A-Z][^_]*_[a-z][^.]*\.html$/; open my $fh, '>', 'badnames.txt' or die $!; while (<DATA>) { print $fh $_ unless m/$re/; } close $fh or die $!; __DATA__ Kilo_Kili_asc.html kilo_Kili_asc.html Jiko_Huji_asc.html Jiko_Huji_asc.htm Puji_huki_asc.html Puji_Huki_Asc.html
qr is a quoting operator which lets you precompile a regex for later use.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: Perl Scripting for testing
by g0n (Priest) on Mar 31, 2005 at 08:58 UTC
    Since the OP states that he/she is a beginner with perl, some explanation of Zaxos regex might be useful.

    From the left:

    • /^[A-Z] - the / starts the expression, the ^ means 'at the beginning of the string', the square brackets mean 'any of these characters', and the A-Z means 'the range from A to Z'
    • [^_]* - match a number of characters that are not underscores. In this context the ^ character means NOT, rather than its other meaning as 'beginning of line'
    • \.html$/ - the \ escapes the dot, which would otherwise (in a regex) mean 'any character', html is obvious, then the regex closes with $, meaning 'end of string', and finally the / ends the expression.

    The rest of the regex is either plain characters, or variations on these, so thats probably sufficient.

    g0n, backpropagated monk
      In the mainstream of understanding REs, (s)he could also find useful YAPE::Regex::Explain, as suggested by davis in this post, which really revealed me a whole world!

      Flavio

      Don't fool yourself.