Michael Alipio wrote:

Here's what I came up with:

#!/usr/bin/perl
use warnings;
use strict;


my $wordlist = shift @ARGV;

open INPUTFILE, "$wordlist" or die $!;



while (<INPUTFILE>){
# Find all words that are 6-15 characters with at
least 2 digits and 4 letters that can appear anywhere

next unless (
    /\b\w{6,15}\b\n/ &&

- The \w character class includes the underscore character, which is probably
why Paul wrote his solution the way he did. Whether this is acceptable or not
is up to you. [[:alnum:]] is also available if you prefer it

- There is no point in putting \b before \n at the end of your regex as a \w
character followed by a newline will necessarily contain a word boundary

- You say the word can appear anywhere but you are finding the last word in
the line. Surely the entire line should be tested, and any junk that happens
to end in a valid string isn't acceptable?


    /.*(\d).*\d/ &&

This will match a string containing at least two digits, and capture the first
one into $1. Paul warned against using regexes for everything and the tr//
character count he proposed is much more concise for your purpose:

 tr/0-9// >= 2


    /(.*([a-z]|[A-Z]).*){4}/);

This will match a string that contains at least four alphabetic characters,
capture the last of them into $1, and the last of them and everything
following into $2. But it's not at all clear either what it does or whether
it works. Again, the solution with tr// is much better:

 tr/a-zA-Z// >= 4

print;

}

[snip]

Rob

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to