TJCooper has asked for the wisdom of the Perl Monks concerning the following question:
Hi, I've created a very basic Perl script to generate combinations of words:
use strict; use warnings; use Algorithm::Combinatorics qw(combinations); my $strings = [qw(Word1 Word2 Word3 Word4)]; my $iter = combinations($strings, 2); while (my $c = $iter->next) { print "@$c\n"; }
How would I go about using words from a .txt file rather than manually adding them (GGGG CCCC...). I understand the basics of opening and reading (line-by-line) files in perl but I am not sure how to use this data within the above script. My .txt file is essentially:
Word1 Word2 Word3 Word4
And so on. Can I use something like:
open (DATA, "text.txt"); @Test = <DATA>; close DATA;
To open/read it? Not sure how to then get Perl to use the loaded data. Can anybody offer any assistance? Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using imported .txt file with Algorithms::Combinatorics
by LanX (Saint) on Jan 08, 2014 at 12:26 UTC | |
by TJCooper (Beadle) on Jan 08, 2014 at 12:40 UTC | |
by LanX (Saint) on Jan 08, 2014 at 12:48 UTC | |
by TJCooper (Beadle) on Jan 08, 2014 at 13:01 UTC | |
by tangent (Parson) on Jan 08, 2014 at 13:16 UTC | |
|