http://qs321.pair.com?node_id=1109752

prensrf has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

Sorry for the poor title, my inability to describe my problem is probably why I haven't been able to search for a suitable answer to the issue.

Basically I have been trying to compare values held in multiple lists and generate some output based on the position in the list of the match.

After some searching around I came across an interesting snippet of code using Algorithm::NeedlemanWunsch

However, this is the problem. The Snippet uses scalars as the input. . .

my $arr1 = [qw(A T C G T C G A G C G)]; my $arr2 = [qw(A C G T C C T G T C G)];
and I have the values I need to push into the algorithm in two @lists

Can anyone suggest a way to mangle my @lists into a suitable scaler in the above format?

Thanks in advance

Rich

Replies are listed 'Best First'.
Re: array to string conversion.
by choroba (Cardinal) on Dec 09, 2014 at 15:28 UTC
    qw() creates a list of strings. [...] makes it an anonymous array, i.e. an array reference. So, for @list1 and @list2, you can just
    my $arr1 = \@list1; my $arr2 = \@list2;

    or, if you don't want to work directly with the lists, copy them:

    my $arr1 = [ @list1 ]; my $arr2 = [ @list2 ];
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: array to string conversion. (perlintro, perlreftut, perldata)
by Anonymous Monk on Dec 09, 2014 at 15:30 UTC
Re: array to string conversion.
by Ratazong (Monsignor) on Dec 09, 2014 at 15:30 UTC

    You can use

    • join to transform an array into a string
    • split to split a string into an array

    HTH, Rata
Re: array to string conversion.
by prensrf (Initiate) on Dec 09, 2014 at 15:42 UTC

    Doh!

    Thanks to all, i'd been struggling to make anything work with join, and it's been a few years since i've done any serious perl coding.

    The reference worked a treat

    Thanks again

Re: array to string conversion.
by sundialsvc4 (Abbot) on Dec 09, 2014 at 16:53 UTC

    It’s also sometimes very useful to use Data::Dumper to display for you exactly what a data-structure actually looks like.   Although the “actual” world of Perl only contains lists, arrays, and so-on, the presence of “references” (and a very-generous syntax which assumes you know what you want and which gives you more-than-one way to say it) can make it hard to visualize what you’re actually looking-at and/or what you’re actually going to get.   The Dumper is a good tool for, show me...”

      It’s also sometimes very useful to use...

      Not when you don't know basic syntax sundialsvc4, you have to learn basic syntax first before DD is useful