Leser: 27
1 2 3 4
# my %seen = map $_ => 1, split //, $string1; my %seen = map { $_ => 1 } split //, $string1; my $merged = $string1; not $seen{$_} and $merged .= $_ for split //, $string2;
QuoteOdd number of elements in hash assignment at ./test.pl line 9.
1 2 3 4 5 6 7 8 9 10
#!/usr/bin/perl use strict; use warnings; my $string1 = 'abcdef'; my $string2 = 'efghijk'; my %seen = map $_ => 1, split //, $string1; my $merged = $string1; not $seen{$_} and $merged .= $_ for split //, $string2;
my %seen = map { $_ => 1 } split //, $string1;
2009-04-09T14:46:52 leo11Wie funktioniert hier das \1 ?
2009-04-09T15:14:09 Linuxerbtw. die zweite Klammerung (um die \1) ist nicht notwendig ;o)
1 2 3 4 5 6
my $s1 = 'abcdef'; my $s2 = 'efghijk'; my $m = $s1 . "\0" . $s2; $m =~ s/(\w+)\0(\1)/$1/; print $m;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; my $string1 = 'abcdef'; my $string2 = 'efghijk'; foreach my $letter (split //, $string2){ $string1 =~ s/$letter//g; } my $new_string = $string1.$string2; print "$new_string";
2009-04-09T13:36:32 #Kein KommentarEDIT: ach ne, es könnten ja auch in $string2 buchstaben doppelt vorkommen, deshalb ist meine lösung nicht richtig
1 2
my $merged=""; map{ $merged .= $_ if( $merged !~/\Q$_\E/ ) } split(//, $string1.$string2);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/bin/perl use warnings; use strict; my $s1 = 'abcdef'; my $s2 = 'efghijk'; my $s = $s1 . $s2; my $a; my $i; my $m = ""; for ($i = 0; $i < length($s); $i++) { $a = substr($s, $i, 1); if ($m !~ m/\Q$a\E/) { $m .= $a; } } print "$m\n";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl use warnings; use strict; my $s1 = 'abcdef'; my $s2 = 'efghijk'; my $s = $s1 . $s2; my $m = ""; while(length($s) > 0){ my $z=substr($s, 0, 1, ''); if($m !~ m/\Q$z\E/){ $m .= $z: } } print "$m\n";
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl use strict; use warnings; use List::MoreUtils qw(uniq); my $string1 = 'abcdef'; my $string2 = 'efghijk'; my $merged = join '', uniq map {split //} $string1, $string2;