Task1
We extract the unique numbers:
#!/usr/bin/env perl
use strict;
use warnings;
use Data::Show;
use List::Util qw(uniq);
sub counter_integers{
uniq $_[0] =~ /(\d+)/g
}
print show counter_integers('the1weekly2challenge2');
print show counter_integers('go21od1lu5c7k');
print show counter_integers('4p3e2r1l');
Task2
We find letters which appear both in lower and upper case:
#!/usr/bin/env perl
use strict;
use warnings;
sub nice_string{
my ($str) = @_;
my %h;
$h{lc $_} |= 1 + /[a-z]/ foreach split '',$str;
foreach my $c(keys %h){
next if $h{$c} == 3;
$str =~ s/$c//gi;
}
$str
}
printf "%s\n",nice_string('YaaAho');
printf "%s\n",nice_string('cC');
printf "%s\n",nice_string('A');