Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Problems with strings

by johngg (Canon)
on May 20, 2019 at 15:53 UTC ( #11100290=note: print w/replies, xml ) Need Help??


in reply to Problems with strings

I'm not at all sure I understand your requirement. The query you mention suggests that the easiest thing to do would be to keep the original string along with any transformations. Here's my stab at it.

use 5.026; use warnings; use Data::Dumper; my @strings = qw{ aaaaaaaaabababacbbbbbbbaccaabc aaaaaaaaaaaaaaaaacbbbbbbbaaaca aaaaaaaaabaaaaabbaaaaabaaccccc }; homogenise( \ @strings ); print Data::Dumper->Dumpxs( [ \ @strings ], [ qw{ *strings } ] ); sub homogenise { my $raStrings = shift; my $len = length $raStrings->[ 0 ]; foreach my $string ( @{ $raStrings } ) { $string = { original => $string }; $string->{ byLine } = join q{}, sort split m{}, $string->{ original }; } my $allSorted = join q{}, sort map { split m{}, $_->{ original } } @{ $raStrings }; my $idx = 0; $raStrings->[ $idx ++ ]->{ bySet } = $_ for unpack qq{(a$len)*}, $allSorted; }

The output.

@strings = ( { 'bySet' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa', 'original' => 'aaaaaaaaabababacbbbbbbbaccaabc', 'byLine' => 'aaaaaaaaaaaaaaabbbbbbbbbbbcccc' }, { 'byLine' => 'aaaaaaaaaaaaaaaaaaaaabbbbbbbcc', 'original' => 'aaaaaaaaaaaaaaaaacbbbbbbbaaaca', 'bySet' => 'aaaaaaaaaaaaaaaaaaaaaaaaaaabbb' }, { 'byLine' => 'aaaaaaaaaaaaaaaaaaaaabbbbccccc', 'bySet' => 'bbbbbbbbbbbbbbbbbbbccccccccccc', 'original' => 'aaaaaaaaabaaaaabbaaaaabaaccccc' } );

I hope that this is vaguely in the direction you are wanting to go.

Cheers,

JohnGG

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11100290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2020-06-07 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (42 votes). Check out past polls.

    Notices?