Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Multidimensional arrays within arrays

by reaper9187 (Scribe)
on Jan 23, 2013 at 08:19 UTC ( #1014859=note: print w/replies, xml ) Need Help??

in reply to Multidimensional arrays within arrays

Thank you everyone for their suggestions.. Some smart manipulation of the data helped me get rid of this problem but a new problem has cropped up. I have grouped the data together and referenced the array as push(@{$variable[0]}, #some values);
But the value $variable is generated within the subroutine and i need to export this information to some other subroutine that is called by the user ( to plot the graph). As such, i was thinking of defining these arrays as global variables so that it can be easily accessed by the user without having to call the parent subroutine which generates these arrays(after first run). For eg: SubA generates these arrays. I need to call sub B(called by another subroutine C) that plots the graphs

Currently, i am able to generate the graphs within the same subroutine. I need to globalize these arrays.I cannot pass these arrays as arguments to sub C directly. My problem is with defining these dereferenced hashes(eg: @{$variable[0]}) within Sub A as global variables . How do i do that ???

Replies are listed 'Best First'.
Re^2: Multidimensional arrays within arrays
by muba (Priest) on Jan 23, 2013 at 11:25 UTC

    Why can't you pass the coordinates to sub C?

    And do you call sub B, or does sub C call sub B? I think I'm distilling the notion that you want C to call B, am I right? Let's roll with that.

    Why would this not work for you?

    sub subA { # ... # generate array; # here be dragons, an' arrays an' pushes an' references # an' lots of dereferencing happens here, me lad. # ... return \@array; } sub subB { my $chart_widget = shift; my $data_aref = shift; $chart_widget->chart( $data_aref ) # or however Tk::Chart be used, + matey } sub subC { my $chart_widget = shift; my $data_aref = shift; # ... # I don't have a clue what be happenin' here, me hearty. # ... subB($chart_widget, $data_aref); }

    And from your main code:

    my $chart = $mw->Chart( ... ); my $data_aref = subA; subC($chart, $data_aref);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1014859]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2018-04-23 06:22 GMT
Find Nodes?
    Voting Booth?