Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
## Declare few single dimensional array my @row1 = qw(71 22 15 10 51); my @row2 = qw(91 82 28 11 91); my @row3 = qw(11 72 37 58 20); my @row4 = qw(21 42 63 24 16); my @row5 = qw(81 32 53 54 42); ## Adding all the single dimensional array reference into another arra +y my @array_2d = (\@row1, \@row2, \@row3, \@row4, \@row5); print "Print Using Array Index\n"; for(my $i = 0; $i <= $#array_2d; $i++){ # $#array_2d gives the highest index from the array for(my $j = 0; $j <= $#array_2d ; $j++){ print "$array_2d[$i][$j] "; } print "\n"; }

Is there any way to pass dynamic array values in my @array_2d i.e by using some loop ...

Thanks Jit

Sorry Monks, I din't explained my questions well. Below is the part of my code were I store the coordinates in @{"$speciesName"."_brk"}; Now every time I need to change the @matrix=\(@species,@chromosome,@brk_cordinates,@brk_decision,@chimp_brk,@dog_brk,@horse_brk,@human_brk,@monkey_brk,@pig_brk,@rat_brk); and undef at the end manually. I need to get rid of it. Note: @unique_species and @target_species is not fix, it can be anything.

for ($aaa=0; $aaa<=$#unique_species; $aaa++) # The @unique +_species is Chimp,Dog,Horse,Human,Monkey,Pig,Rat { @brk_species_name=split /\_/,$unique_species[$aaa]; my $speciesName= lc($brk_species_name[0]); @{"$speciesName"."_brk"}=0; foreach $cor(0..$#target_species) { if ("$target_species[$cor]" eq "$unique_species[$a +aa]") { #print "$target_species[$cor]\t$unique_species +[$aaa]\t$target_brk_cordinates[$cor]\n"; push @{"$speciesName"."_brk"},"$target_brk_co +rdinates[$cor]"; } } @{"$speciesName"."_brk"}=sortUniqueHash (@{"$speciesN +ame"."_brk"}); my $arrayEntries=checkNumber (@{"$speciesName"."_brk"} +); push (@allDecision, $arrayEntries); push (@allBreakpointCoordinates, @{"$speciesName"."_br +k"}); @{"$speciesName"."_brk"}=join (',',@{"$speciesName +"."_brk"}); ## it generate one string and enter in an array } # Chimp,Dog,Horse,Human,Monkey,Pig,Rat same order as s +ps file names in matrix .... Need to change ... @matrix=\(@species,@chromosome,@brk_cordinates,@brk_decisio +n,@chimp_brk,@dog_brk,@horse_brk,@human_brk,@monkey_brk,@pig_brk,@rat +_brk); #print "Print Using Array Index\n"; for(my $i = 0; $i <= $#matrix; $i++){ # $#array_2d gives the highest index from the array for(my $j = 0; $j <= $#matrix ; $j++){ print OUTFILE "$matrix[$i][$j] "; } print OUTFILE"\t"; } print OUTFILE "\n"; undef @target_species; undef @species; undef @chromosome;undef @matri +x; undef @brk_cordinates; undef @target_brk_cordinates; undef @da; + undef @brk_decision; undef @dog_brk; undef @horse_brk; undef @monkey_brk; undef @pig_brk; u +ndef @human_brk; undef @chimp_brk; undef @rat_brk; undef @mouse_brk; +undef @pig_brk; undef @dog_brk; undef @horse_brk; undef @cattle_brk; +undef @allBreakpointCoordinates; undef @all_sps_array; undef @allDecision; undef @matrix;

In reply to 2d array by jnarayan81

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 surveying the Monastery: (8)
As of 2024-03-28 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found