Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Problems with strings

by johngg (Canon)
on May 20, 2019 at 15:53 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11100290]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found