Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Here are 11 changes/simplifications to make your script work
#!/usr/bin/perl #1 add use strict use strict; use warnings; #2 add '' use File::Glob('bsd_glob'); #3 declare variables my (@array,@DNA,@list); my ($filename,$combi,$entry,$number,$DNA); do { #4 not needed @array=@array1; 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): "; $filename = <STDIN>; chomp $filename; unless ( open(FILE, $filename) ) { print "Cannot open file \"$filename\"\n\n"; exit; } @DNA= <FILE>; close FILE; #5 add chomp chomp(@DNA); #6 add join by comma $DNA = join(',',@DNA); push @array, $DNA; #7 not needed @array1=@array; } elsif ($entry==2) { #8 @array1 not needed use @array #@array1=@array; # Curly brace for entry2 starts $number=@array; print"\n\n No. of Elements in Joined Array: $number\n"; print"\n Joined Array:\n"; print "@array\n"; #9 none of this code required because comma added a #6 # Use of foreach LOOP to view each element of joined array: #num=0; #foreach my $element (@array1) { # $num++; # print"\n Array No.$num of the Joined Array:\n"; # print $element; # print"\n"; # Code to surround each element of joined array # followd by comma i.e. [ ], # @element=split('',$element); # $str1 = sprintf '[%s],'x @element,@element; # print"\n str1: $s\n"; #push @ARRAY1,$element; #} # Curly brace for foreach ends: #print"\n ARRAY:\n"; #print @ARRAY1; #print"\n"; # To produce all possible combinations of different elements: #10 use simple $_ on @array #$combi = join('',map {'{'.join (',',@$_).'}'} @ARRAY1); $combi = join('',map {'{'.$_.'}'} @array); print "combi = $combi\n"; @list = bsd_glob($combi); print"\n Results:\n"; #11 print each element on new line print join "\n",@list; } # Curly brace for Entry 2 ends: } until ($entry==2); # Square bracket for do-until: exit;
poj

In reply to Re^5: How can one get all possible combinations of elements of different arrays using File::Glob(bsd_glob)? by poj
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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (14)
    As of 2014-09-16 18:05 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (40 votes), past polls