in reply to Getting out an array within an array
Welcome, sokatron!
sundialsvc4 did an excellent(!) job addressing the concept of a reference to assist you with resolving your array issue.
Although unsolicited--and I apologize in advance if I've confused the issue here--consider the following which doesn't use the C-stype for loop (e.g., for ($x=0; $x<$size; $x++)):
#!/usr/bin/perl use strict; use warnings; print "How many replicates? "; chomp( my $antal = <> ); print "How many Samples? "; chomp( my $size = <> ); my @a; # Consider a more descriptive name for this array. for my $tim ( 0 .. $size - 1 ) { #For each Sample the number of replic +ates are entered for my $tam ( 0 .. $antal - 1 ) { #For each replicate in the sampl +e a value is added print 'Enter replicate value ' . ( $tam + 1 ) . ' for sample ' . ( $tim + 1 ) . ': '; chomp( my $repValue = <> ); $a[$tim][$tam] = $repValue; #push @{ $a[$tim] }, $repValue; # This notation can be used, t +oo. Is there a "Golden Ticket" here? } print "\n"; } for my $tim ( 0 .. $size - 1 ) { #For printing and checking all values print 'Replicates of sample ' . ( $tim + 1 ) . "\n\n"; for my $tam ( 0 .. $antal - 1 ) { print 'Replicate ' . ( $tam + 1 ) . " value is: $a[$tim][$tam] +\n"; } print "\n"; }
Hope this is helpful.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting out an array within an array
by sokatron (Initiate) on Oct 02, 2012 at 06:45 UTC |