in reply to Re: Scope of a Hash
in thread Scope of a Hash

I'm still not getting exactly what I wanted here are some lines of code that I am using. I've posted the lines related the hash that I'm having trouble with). The code is not as efficient as you'll probably think but I'm working on it. On the main application:
%returnVals = (); %X_Axis = (); %Y_Axis = (); $ExcelLink = &swOpenExcel("FILE", $lAppName, $wbFullDirectory, $wbChar +tDirectory, $wbExcelName, $wbExcelData, $dataCol, $strtRow, $labelCol +, $endRow, $typeGraph, $ChartName, $lChartTitle, 'JPG', $lLegendKey, +$lData_Labels, $fields{$q->param(X_Col)}, $fields{$q->param(Y_Col)}, +\%returnVals, \%X_Axis, \%Y_Axis);
In the module:
($typeData, $AppName, $wbFullDirectory, $wbChartDirectory, $wbExcelNam +e, $wbExcelData, $dataCol, $strtRow, $labelCol, $endRow, $typeGraph, +$ChartName, $ChartTitle, $filter, $LegendKey, $LegendType, $rVals, $X +, $Y) = @_; my %X_Axis = %$X; my %Y_Axis = %$Y; my %returnValues = %$rVals; $returnValues{"ExcelLink"} = "/Web$AppName/Charts/" . $wbExcelName . " +_" . $extension . "\.xls";

Replies are listed 'Best First'.
Re^3: Scope of a Hash
by Anonymous Monk on Dec 15, 2005 at 18:00 UTC
    my %returnValues=%$rVals; does not setup an alias, as you seem to assume, but copies the $rVals hash. If you change the copy afterward with $returnValue{"ExcelLink"}=... the original doesn't follow. Either copy back with %$rVals=%returnValues; or change the original instead with $rVals->{"ExcelLink"}=...
Re^3: Scope of a Hash
by blazar (Canon) on Dec 15, 2005 at 17:10 UTC
    I'm still not getting exactly what I wanted here

    If you don't get it, then how do you expect us to? ;-)

    Jokes apart, at first sight your code seems more complex then it may actually be. Can you consider refactoring it in a more "efficient" (human-wise!) way? Said this, an advice that pairs well with the good "do not use typeglobs for this" one is: do not use the &-form of sub call: it is not necessary and obsolete in modern perls. It may be safe enough, but it doesn't do what you want and it's still there for another purpose: see perldoc perlsub.

Re^3: Scope of a Hash
by nedals (Deacon) on Dec 16, 2005 at 00:13 UTC
    $ExcelLink = &swOpenExcel( .. 21 variables .. ); sub swOpenExcel { ## I assume ( ... 19 variables ... ) = @_;

    That is going to cause you some severe problems.

    I would also recomend you rename $rVals, $X, and $Y to something like $rVals_ref, $X_ref, and $Y_ref just to remind you that you are using refs into the future.