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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
test for array of arrays


New User

May 6, 2009, 7:04 AM

Post #1 of 3 (899 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.


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


May 6, 2009, 9:15 AM

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

look into the ref function:

New User

May 6, 2009, 2:48 PM

Post #3 of 3 (881 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


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


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

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



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

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