-
Notifications
You must be signed in to change notification settings - Fork 351
Expand file tree
/
Copy pathch-1.pl
More file actions
34 lines (24 loc) · 668 Bytes
/
ch-1.pl
File metadata and controls
34 lines (24 loc) · 668 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package main;
use strict;
use warnings;
sub first_unique_char {
my $what = shift;
my %seen_chars;
my $pos = 0;
while ( $pos < length($what) ) {
my $char = substr( $what, $pos, 1 );
return $char
if ( index( $what, $char, $pos + 1 ) == -1 )
and ( not exists( $seen_chars{$char} ) );
# This is needed for the case LL, otherwise it would not detect the second L
$seen_chars{$char} = 1;
$pos++;
}
return '';
}
use Test::More;
is( first_unique_char("Perl Weekly Challenge"), "P" );
is( first_unique_char("Long Live Perl"), "o" );
is( first_unique_char("LL"), "" );
done_testing;
1;