Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^5: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)? by hdb
in thread How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)? by supriyoch_2008

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-24 05:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found