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

Re: Getting out an array within an array

by Kenosis (Priest)
on Oct 01, 2012 at 20:47 UTC ( #996743=note: print w/replies, xml ) Need Help??

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
    Yes! I think you figured from my code I have not been programming a lot, and the little I did was C. I will start making the code nicer when I have learned the concepts I need. But it is helpful, this would be how my code would look in perl and not in C, and it will be easier to get the examples from the tutorials if I know how the thing I want "should" look like.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (15)
As of 2016-10-28 13:47 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (383 votes). Check out past polls.