in reply to Re: searching for strings
in thread searching for strings

Tried that one also. It doesn't work either.

C:\test>perl my @d = qw(AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC +50); my $last = ""; foreach my $v ( sort {$a cmp $b} @d) { my $l1 = $last; my $l2 = chop $l1; print "$last,$v\n" if $v eq $l1.++$l2; $last = $v; } ^Z AAA30,AAA31 DAL33A,DAL33B SHT12G,SHT12H

BBC5;BBC6 and BBC49;BBC50 are missing. Working out why is interesting.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^3: searching for strings
by oha (Friar) on Aug 06, 2007 at 13:13 UTC
    right sorry! cauz i can't expect the sorting of BBC5 and BBC6 without BBC50 beetween.
    the following works:
    my @d = qw(AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC +50); my %seen; map { print "$seen{$_},$_\n" if $seen{$_}; } map { my $v = $_; my $l = chop $v; $seen{$v.++$l}=$_; } @d;
    and nicer, imho :)

    Oha

      Typo corrected and enstricted

      my @d = qw(AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC +50); my %seen; map { print "$seen{$_},$_\n" if $seen{$_}; } map { my $v = $_; my $l = chop $v; $seen{$v.++$l}=$_; } @d; __END__ SHT12G,SHT12H DAL33A,DAL33B AAA30,AAA31 BBC5,BBC6

      BBC49,BBC50?

      my @d = qw(AAA30 BBC5 SHT12H DAL33B BBC49 AAA31 DAL33A BBC6 SHT12G BBC +50); my %seen; map { print "$seen{$_},$_\n" if $seen{$_}; } map { (my $v = $_ ) =~ s/(\d+|[A-Z])$//; my $l = $1; $seen{$v.++$l}=$_ +; } @d; __END__ SHT12G,SHT12H DAL33A,DAL33B AAA30,AAA31 BBC5,BBC6 BBC49,BBC50