Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?

by hdb (Parson)
on Apr 24, 2013 at 05:36 UTC ( #1030281=note: print w/ replies, xml ) Need Help??


in reply to How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?

Just a few hints as code snippets:

# declare string for glob my $string = ""; # slurp in file into a string $/=''; $DNA = <FILE>; # remove \n at end chomp($DNA); # replace line endings with commata $DNA =~ s/\n/,/; # surround with braces $DNA = "{$DNA}"; # $DNA should now be good for glob $string .= $DNA; # repeat for each file, don't forget to open and close


Comment on Re: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
Download Code
Re^2: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)?
by jwkrahn (Monsignor) on Apr 24, 2013 at 06:45 UTC
    # slurp in file into a string $/=''; $DNA = <FILE>; # remove \n at end chomp($DNA);

    You have set $/ to paragraph mode so it will not "slurp in file", just the first paragraph of the file.    Also the value of $/ will effect what chomp removes (hint: paragraph mode removes more than just a single \n character).



    # replace line endings with commata $DNA =~ s/\n/,/;

    That replaces a single newline.    If you want to replace ALL newlines then:

    # replace newlines with commas $DNA =~ s/\n/,/g;

    Or perhaps:

    # replace newlines with commas $DNA =~ tr/\n/,/;

      All correct. I should have stated that I was only giving some hints rather than a functioning script.

      UPDATE: The code below works hopefully and has no side effects hopefully?

      use strict; use warnings; my $string = ""; my $DNA; { local $/=undef; $DNA = <DATA>; } chomp($DNA); $DNA =~ s/\n/,/g; $DNA = "{$DNA}"; $string .= $DNA; print $string; __DATA__ C1G1 C1G2 C2G1

        Hi hdb,

        Thanks for the code snippets and update. Honestly speaking, I do not understand exactly where I have to make the changes in my script with the codes given by you in update for getting correct results from the script. I think I have to read more about the use of File::glob perl module and look for examples online to understand the stuff. Using the code given by you I have found that the cmd shows the result {C1G1,C1G2,C2G1}. I find it difficult how to use this in my script to solve the problem.

        With kind regards,

        Here goes the output of cmd:

        Microsoft Windows [Version 6.1.7600] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\x>cd desktop C:\Users\x\Desktop>t9.pl {C1G1,C1G2,C2G1} C:\Users\x\Desktop>t9.pl

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1030281]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (9)
As of 2014-07-28 10:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (196 votes), past polls