Hi Christian.

On Thursday 04 November 2010 11:16:46 Christian Stalp wrote:
> Hello together,
> I try to write some arrays into arrays using references.
> 
> my ($a, $b, $c, @mytemp, $myref, @my_globael_array)

Your code won't compile - you've mis-spelt "global" and you're missing a 
trailing semicolon. Also you shouldn't call lexical variables "$a" and "$b" 
because it interferes with the built-in $a and $b ones used for sorting.

> 
> while(<$myfile>)
> {
>    ($a, $b $c ) = getparameter();

Missing a comma here.

>    @mytemp = ($a, $b, $c);
>    $myref = \...@mytemp;
>    push(@my_global_array, $myref);

Your problem is that you're using the same physical array everytime when 
pushing its arrray ref to @my_global_array.

Either:

1. Do:

push @my_global_array, [...@mytemp];

Or:

2. Declare @mytemp using my inside the loop, so you'll get a different 
instance any time.

You don't need $myref here for anything, and you can do <<my @mytemp = 
getparameter();>>.

Finally, it is a bad practice to declare all the variables at the top, as code 
like yours demonstrates.

Regards,

        Shlomi Fish

> }
> 
> But if I dismantle @my_global_array I get only the last entry, the last
> array.
> 
> Where is the problem?
> 
> Thank you all
> 
> Christian

-- 
-----------------------------------------------------------------
Shlomi Fish       http://www.shlomifish.org/
Rethinking CPAN - http://shlom.in/rethinking-cpan

<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to