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

open (my $filehandle, "<", "text.txt") or die "Problem opening text.tx +t: $!"; @test = <$filehandle>; close $filehandle; chomp @test;

should do, if every line has exactly one entry.

Untested ...

see open for more examples and perlintro#Files-and-I/O¹ for general pointers to even more documentation.

Do you need suggestions for good Perl books?

Cheers Rolf

( addicted to the Perl Programming Language)

updates

¹) strange that perlintro doesn't mention chomp

Replies are listed 'Best First'.
Re^2: Using imported .txt file with Algorithms::Combinatorics
by TJCooper (Beadle) on Jan 08, 2014 at 12:40 UTC

    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?

      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?