in reply to Re: Using imported .txt file with Algorithms::Combinatorics
in thread Using imported .txt file with Algorithms::Combinatorics

Thank you! Suggestions for good books would be great. I need something that builds up the foundations more than anything. Perl seems like a really amazing language but I haven't come to grips with an efficient way to learn it - and have instead just been looking at and editing existing scripts. For now, I am simply curious to see how you could then take @test and use it to replace

my $strings = [qw(GGGG CCCC TTTT AAAA)];

such that the words in the .txt file are combined. Would you mind showing me?

Replies are listed 'Best First'.
Re^3: Using imported .txt file with Algorithms::Combinatorics
by LanX (Saint) on Jan 08, 2014 at 12:48 UTC
    in a complicated way:

    my $strings = \@test;

    easier

    @$strings = <$filehandle>;

    ATM I'm in a hurry ... others might recommend you books. =)

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      Thank you for the help! That has clarified some things for me.

      #!/usr/bin/env perl open (my $data, "<", "test.txt") or die "There was a problem opening: +$!"; my @primers = <$data>; close $data; chomp @primers; use strict; use warnings; use Algorithm::Combinatorics qw(combinations); my $strings = \@primers; my $iter = combinations($strings, 2); while (my $c = $iter->next) { print "@$c\n"; }

      I'm now running this and it mostly does what I intended it to do. My output ends up putting an unwanted space in-between the 2 words that were combined. Is this because i'm stringifying?

        an unwanted space in-between the 2 words that were combined
        Replace the print statement with something like:
        print join('',@$c) ."\n";