The key is in the glob function. If you feed it a string like "{1,2}{a,b,c}" it creates all combinations of elements within the braces. Here is a complete solution for your problem. I hope you can adapt it to your needs. There is nothing really new in there.
use strict;
use warnings;
use File::Glob qw{bsd_glob};
my $string;
my $entry;
do {
print"\n\n Press 1 to Enter New File or 2 to Combine: ";
$entry=<STDIN>; chomp $entry;
if ($entry==1) {
print"\n\n Enter New File Name (.txt): ";
my $filename = <STDIN>;
chomp $filename;
open my $fh, "<", $filename or die "Cannot open $filename.\n";
my $DNA;
{
local $/=undef;
$DNA = <$fh>;
}
close $fh;
chomp $DNA;
$DNA=~s/\n/,/g;
$string .= "{$DNA}";
} # Curly brace for entry1 ends:
} until ($entry==2);
for (bsd_glob $string) {
print "~$_~\n";
}
So for every file you input, it creates this substring "{...,...,...}" with all elements from the file and adds it to the previous substrings of the same kind. When you are done, the overall string is fed into glob to create all combinations. I hope this makes it clear.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|