[Solved] Perl set counter to match in loop

[ad_1]

If you only want to increment unless some condition is met,
you should mention that in your code.

Using the postfix foo() unless condition(); syntax means the condition will only refer to the previous statement, not the entire scope ( which would arguably be insane to parse ).

So print '...' unless $foo is the same as unless( $foo ){ print '...'; }.

Thus, if you want to include more than one statement in your unless condition, you need to use curly braces: unless ( $foo ) { # as many lines as desired }

If I understood your question correctly, you want to do:

unless ( $justone{$1}++ ){
    $count++;
    print "Number:$count Your TLD $1!\n"
}

This will increment only if the condition was met, and lead to the desired output. I would suggest to use a named variable for what you’ve captured in $1 to make it more readable, though.

[ad_2]

solved Perl set counter to match in loop