in reply to Re^3: RegEx Question
in thread RegEx Question

Thanks for the reply... I was really hoping for a easy way out...!! :)

Replies are listed 'Best First'.
Re^5: RegEx Question
by GrandFather (Saint) on Sep 09, 2009 at 22:12 UTC

    It depends a great deal on what you consider to be 'easy' and probably also it depends what it is that you actually want to achieve. The following code may help:

    use strict; use warnings; for my $number (1233456, 10, 1, 555789041) { my %digits; my @failDigits = grep {++$digits{$_} == 2} split '', $number; next if ! @failDigits; print "Number $number failed for:\n"; print " $_: $digits{$_} places\n" for @failDigits; }

    Prints:

    Number 1233456 failed for: 3: 2 places Number 555789041 failed for: 5: 3 places

    True laziness is hard work