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:
test for array of arrays

 



yankee338
New User

May 6, 2009, 7:04 AM

Post #1 of 3 (517 views)
test for array of arrays Can't Post

I have a ref to an array. If it's a single value, then warn Dumper($allresults)->[0][0] will cause the code to fail, but an array of arrays will work. So, I'm trying to build an if statement to test if it is an array of arrays. I thought i could do this

if (exists $allresults->[0][0]) {

warn "it is array of array";

}

but the problem is that this fails due to "can't use string ("111.9") as an ARRAY ref while "strict refs" in use. How can I test if this is an array of array or not. I'm not interested in removing the use strict requirement.



Thanks


(This post was edited by yankee338 on May 6, 2009, 7:43 AM)


KevinR
Veteran


May 6, 2009, 9:15 AM

Post #2 of 3 (506 views)
Re: [yankee338] test for array of arrays [In reply to] Can't Post

look into the ref function:

http://perldoc.perl.org/functions/ref.html
-------------------------------------------------


yankee338
New User

May 6, 2009, 2:48 PM

Post #3 of 3 (499 views)
Re: [KevinR] test for array of arrays [In reply to] Can't Post

Thanks so much Kevin, that is perfect. I ended up shortcutting

from

if (ref($r) eq "ARRAY") {

to

if (ref $r->[0] ) {

therefore, if first element in array is an array, then run code, else it is not an array of arrays

Yahoooee!

 
 


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

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