Please show some simple input and output. I didn't completely understand your question.
The below code shows some common techniques. If you want sequences of digits (a list of solutions) that don't repeat, the code is different, but not by much.
#!/usr/bin/perl -w use strict; use Data::Dumper; my @test =(112,1234,1424); foreach (@test) { if (is_num_repeated($_) ) { print "$_ FAILED digit is repeated\n"; } else { print "$_ OK no digit repeated\n"; } } foreach (@test) { print "no_repeat: $_ string before repeat is: ", first_non_repeating_digits($_),"\n"; } sub is_num_repeated { my $num = shift; my @digits = split(//,$num); my %seen; foreach (@digits) { $seen{$_}++; } # this is grep in a scalar context... return (grep {$_ >1} values %seen); } sub first_non_repeating_digits { my $num = shift; my @digits = split(//,$num); my %seen; my $result; foreach (@digits) { return $result if ($seen{$_}++); $result .= $_; } return $result; } __END__ 112 FAILED digit is repeated 1234 OK no digit repeated 1424 FAILED digit is repeated no_repeat: 112 string before repeat is: 1 no_repeat: 1234 string before repeat is: 1234 no_repeat: 1424 string before repeat is: 142
In reply to Re: RegEx Question
by Marshall
in thread RegEx Question
by yoda54
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |