On Nov 1, 1:37 pm, [EMAIL PROTECTED] (Jl Post) wrote:
> On Nov 1, 9:35 am, [EMAIL PROTECTED] (Charles) wrote:
>
>
>
> > I have module from CPAN named Graph. I have created a subroutine for
> > this to pass in two arrays; x-axis and y-axis into my Graph subroutine
> > i.e. ; &graph( @Xvalues,  @Yvalues );
>
> > My confusions is: in my subroutine, I cannot treat the two parameters
> > (arrays) as separate parameters.
>
> Dear C. Carson,
>
>    That's right.  InPerl, you usually cannot treat two arrays as
> separate parameters.  As a result, your line:
>
>       graph( @Xvalues,  @Yvalues );
>
> is functionally equivalent to the following two lines:
>
>       my @array = ( @Xvalues, @Yvalues );
>       graph( @array );
>
> which I'm guessing is not what you meant.
>
>    To do what you want, you need to pass in two scalar values as
> parameters (each representing one array), and then extracting the
> arrays out in the graph() function.  For example, you'd call your
> graph() function like this:
>
>       graph( [EMAIL PROTECTED], [EMAIL PROTECTED] );
>
> The '\' character (in front of both arrays) returns a scalar reference
> to its array, which is then sent into the graph() function.
>
>    However, in your graph() function $_[0] and $_[1] will not be set
> to the arrays, but rather the references to the arrays.  You must do
> something like this in your graph() function to de-reference them:
>
>       sub graph
>       {
>          my @Xvalues = @{ $_[0] };  # remember to use "my"!
>          my @Yvalues = @{ $_[1] };  # remember to use "my"!
>
>          # The @Xvalues and @Yvalues arrays are now set to what you
> want.
>
>          # (The rest of your code goes here.)
>       }
>
>    I hope this helps, C. Carson.
>
>    -- Jean-Luc

Thank you so much for your help! I will try this and let you know.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to