Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Printing out 3 dimensional arrays.

Reply
Thread Tools

Printing out 3 dimensional arrays.

 
 
John
Guest
Posts: n/a
 
      12-04-2006
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.

 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      12-04-2006
Cheer mate, that is a much better way of doing it.

On 4 Dec, 22:42, "Todd W" <(E-Mail Removed)> wrote:
> "John" <(E-Mail Removed)> wrote in messagenews:(E-Mail Removed) ooglegroups.com...
>
>
>
> > 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.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.
>
> Also, Data:umper is nice for what you are trying to do:
>
> use Data:umper;
> print( Dumper( \@AoAoA ) );
>
> Todd W.


 
Reply With Quote
 
 
 
 
DJ Stunks
Guest
Posts: n/a
 
      12-04-2006
John wrote:
> 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

 
Reply With Quote
 
DJ Stunks
Guest
Posts: n/a
 
      12-04-2006
Todd W wrote:
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
> > 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.

>
> 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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-04-2006
John wrote:
> 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

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      12-04-2006
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.


On 4 Dec, 23:09, "Paul Lalli" <(E-Mail Removed)> wrote:
> John wrote:
> > 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


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      12-04-2006
John wrote:
> 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

 
Reply With Quote
 
Tad McClellan
Guest
Posts: n/a
 
      12-05-2006
Todd W <(E-Mail Removed)> wrote:
>
> "John" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) oups.com...
>> 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 =@{$_};




> 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.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
To convert a one dimensional array into a two dimensional array using C amrutha0303 Software 0 08-03-2010 10:02 PM
How do copy Strings from a single dimensional array to double dimensional array Venkat C++ 4 12-05-2003 09:23 AM
Re: Two dimensional pointers and Two dimensional arrays Icosahedron C++ 8 08-21-2003 05:15 AM
Re: Two dimensional pointers and Two dimensional arrays John Harrison C++ 4 08-19-2003 04:00 PM
Re: Two dimensional pointers and Two dimensional arrays Alf P. Steinbach C++ 0 08-18-2003 08:25 AM



Advertisments