Printing out 3 dimensional arrays.

J

John

Hello, just a little thing. I'm trying to print out a 3 dimensional
array using the following code

for(@AoAoA)
{
my @AoA =@{$_};
for(@AoA)
{
my @array =@{$_};
for(@array)
{
print $_
}
print "\n";
}
print "#################################\n";
}

but i get told that

"Can't use string ("R03210") as an ARRAY ref while "strict refs" in use
at graph.plx line 46."

where line 46 is the line that says "my @array =@{$_};" but I'm sure
that it is a 3 dimensional array
that I am passing it at the start. Thanks.
 
D

DJ Stunks

John said:
Hello, just a little thing. I'm trying to print out a 3 dimensional
array using the following code

for(@AoAoA)
{
my @AoA =@{$_};
for(@AoA)
{
my @array =@{$_};
for(@array)
{
print $_
}
print "\n";
}
print "#################################\n";
}

but i get told that

"Can't use string ("R03210") as an ARRAY ref while "strict refs" in use
at graph.plx line 46."

where line 46 is the line that says "my @array =@{$_};" but I'm sure
that it is a 3 dimensional array
that I am passing it at the start.

I love posts like this. you're sure are you? how sure are you
exactly? the reason I ask is because I'm 1250% sure you're not :)~

have you read the posting guidelines for this group?

-jp
 
D

DJ Stunks

Todd said:
This is why I only use $_ in map or grep.

What is probably happening is once you enter the the first inner loop, $_
from the outer loop is clobbered with the first array item from the inner
loop.

I'm glad you said "probably" and not that you were "sure" like the OP.
because that's not it.

try it, here's an actual 3D array (since the OP didn't provide one):

my @three_d = (
[
[ qw{ 1 2 } ],
[ qw{ 3 4 } ],
],
[
[ qw{ 5 6 } ],
[ qw{ 7 8 } ],
],
);

-jp
 
P

Paul Lalli

John said:
Hello, just a little thing. I'm trying to print out a 3 dimensional
array using the following code

for(@AoAoA)
{
my @AoA =@{$_};
for(@AoA)
{
my @array =@{$_};
for(@array)
{
print $_
}
print "\n";
}
print "#################################\n";
}

but i get told that

"Can't use string ("R03210") as an ARRAY ref while "strict refs" in use
at graph.plx line 46."

where line 46 is the line that says "my @array =@{$_};" but I'm sure
that it is a 3 dimensional array
that I am passing it at the start.

Uh-huh. You're sure. Perl's sure you're not. Perl is infinitely more
likely to be correct than you are. I believe Perl. I don't believe
you.

Try giving some sample data. Try giving a short-but-complete program
that we can run, as suggested by the posting guidelines.

Paul Lalli
 
J

John

I did have a look for posting regulations before posting, but couldn't
find them. I suppose that I should have looked harder. Your right a
short-but-complete program would be a more sensible and constructive
way of presenting the query. But in spite of all my errors the Todd W
managed to give me advice that solved my problem quicker than you
managed to complain about my posts short-comings. So while you're
right to correct my posting style don't you think this group and the
world in general would be a nicer place with less unnecessary rude and
patronising behaviour?


Love, John.

P.s.

Also I'm 'sure' you'll be glad to know that it was a 3 dimensional
array that was printed out after I followed Todd W advice.
 
P

Paul Lalli

John said:
I did have a look for posting regulations before posting, but couldn't
find them.

So you know how to search as well as you know how to program. They're
posted here twice a week. They have the title "Posting Guidelines".
This is not difficult.

I suppose that I should have looked harder. Your right a
short-but-complete program would be a more sensible and constructive
way of presenting the query. But in spite of all my errors the Todd W
managed to give me advice that solved my problem

No, he gave you advice that got you *around* your problem. You clearly
still don't know what a three-dimensional array is, or how to go about
accessing the various levels of it. He gave you a piece of code that
prints out debugging information. Possibly useful for your immediate
needs, but worthless for any "real" programming.

quicker than you
managed to complain about my posts short-comings. So while you're
right to correct my posting style don't you think this group and the
world in general would be a nicer place with less unnecessary rude and
patronising behaviour?

No no, see my post was *necessarily* rude, because so was yours. You
are making the mistake of assuming I was trying to help you. When you
post such a blatantly poor attempt to let us help you, why would I
waste my time attempting to do that?
Also I'm 'sure' you'll be glad to know that it was a 3 dimensional
array that was printed out after I followed Todd W advice.

No. It wasn't. You pretty clearly don't know what a "3 dimensional
array" is. Or you lied about the error message. Or you lied about the
actual code you posted. Either way, you're pretty clearly not worth
helping.

Yes. This was rude. No, I'm not sorry.

Paul Lalli
 
T

Tad McClellan

Todd W said:
What is probably happening is once you enter the the first inner loop, $_
from the outer loop is clobbered with the first array item from the inner
loop.


That is not what is happening.

foreach/for local()izes the loop control variable, there is no
clobbering going on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top