gerry has asked for the wisdom of the Perl Monks concerning the following question:

I am a seeker of your knowledge and hope you can help me clear up my confusion.

I have a graphClient that calls a graphServer via a TCP/IP socket. The graphServer accesses logfiles from previous online activities. From these logfiles, data is extracted to create three (3) arrays. Each array contains 1440 (0-1339) entries, (one for each minute of the day). Each entry contains the sum of the activity for that minute. The arrays are named based on the associated activity, (i.e. @queries, @threads, @restarts). The arrays are being created as I can print them out.

I pass these arrays back to the graphClient so the contents may be acted upon.

graphSocket: @response = "@response" . "," . "@threads" . "@restarts"; print "\@reponse: @response\n"; print $new_sock "@response\n";
I issue a print right after I append them to the @response array and since each is printed, I assume @response now contains them.

The following is how my client is attempting to receive them back:

graphClient: ...graphing routine mevs_get_stats($server, $mb_portno); # get the data from MEV +S Servers print "\nResponse returned from $server:\n$response\n"; # pri +nt response - THIS WORKS! @arrays = split(",", $response); # split queries/threads/rest +arts into @arrays -- DOESN'T WORK? print "\narray[0]: $arrays[0]\n"; # Prints Nothing?? print "\narray[1]: $arrays[1]\n"; # Prints Nothing?? print "\narray[2]: $arrays[2]\n"; # Prints Nothing?? # my @queries = split(" ", $arrays[0]); # split queries my @threads = split(" ", $arrays[1]); # split threads my @restarts = split(" ", $arrays[2]); # split restarts $i = 0; # init $i to 0 prior t +o indexing the matrix print "\nQueries(split response):\n@queries\n"; #debu +g print "\nThreads(split response):\n@threads\n"; #debu +g print "\nRestarts(split response):\n@restarts\n"; #debu +g
In graphClient, the socket routine (mevs_get_stats) is called which calls the server and receives the $response. I print the $response and all is okay, (the commas also print which show the separation of the arrays).

However, once I do my splits and presumably extract the data into separate arrays, I then print each array variables, $array0-2, and get absolutely nothing... At this point, it seems I know longer have any data/arrays.

I know I must be doing something wrong, I'm not sure what it is. I am hoping you can help get me on the right track.

Thanks to everyone for your help.
pcnut

Replies are listed 'Best First'.
Re: How do I create and pass an array of arrays to other modules
by xdg (Monsignor) on Aug 19, 2005 at 18:47 UTC

    Your variable is called '@arrays', but you print '$array[0]' etc. -- which is a different variable. Try:

    print $arrays[0];

    This is an example of where coding with use strict would have helped you.

    -xdg

    Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.

      Thank you for your wisdom. I need glasses! You are right about  use strict. All new projects will use it. Again, thank you.

      Gerry

Re: How do I create and pass an array of arrays to other modules
by poj (Abbot) on Aug 20, 2005 at 08:39 UTC
    Another "," required between @threads and @restarts ?
    @response = "@response" . "," . "@threads" . "@restarts";
    poj