CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Printing Reference array

 



tej.87g
Novice

Sep 27, 2010, 8:25 AM

Post #1 of 3 (319 views)
Printing Reference array Can't Post

Hello, I am passing reference of multidimentional array from one subroutine to second subroutine.
I want to print array in second subroutine can anybody please help me?


rameshg87
Novice

Sep 27, 2010, 9:09 AM

Post #2 of 3 (318 views)
Re: [tej.87g] Printing Reference array [In reply to] Can't Post

It depends on why you want to print the array.

If you want it for debugging purposes, there is a perl module called Data::Dumper.
You can pass any reference to this module and it will print any data structure to any level of depth.


http://search.cpan.org/~smueller/Data-Dumper-2.128/Dumper.pm


BillKSmith
Veteran

Sep 27, 2010, 12:16 PM

Post #3 of 3 (312 views)
Re: [tej.87g] Printing Reference array [In reply to] Can't Post

If the called array knows the dimensions of the array, it can do anything the caller could have done.

Otherwise, it has to get them using the special syntax for size-of-array or for last index. My exmple is restricted to the former case.


Code
  

use strict;
use warnings;
array_maker();

sub array_maker {
my @multi = (
[
[111, 112, 113,],
[121, 122, 123,],
[131, 132, 133,],
],
[
[211, 212, 213,],
[221, 222, 223,],
[231, 232, 233,],
],
[
[311, 312, 313,],
[321, 322, 323,],
[331, 332, 333,],
],
);
array_user(\@multi);
}

sub array_user {
(my $multi_ref) = @_;
my @multi = @$multi_ref;
for my $i (0..2) {
for my $j (0..2) {
for my $k (0..2) {
print $multi[$i][$j][$k], "\n";
}
}
}
}

Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives