Error - 'global symbol requires explicit package name'

前端 未结 1 1962
借酒劲吻你
借酒劲吻你 2021-01-23 16:43

I am trying to write a script for matrix multiplication. Its just a basic program but I am not able to figure it out about the following error :

Global symbol \"@ref_ma

相关标签:
1条回答
  • 2021-01-23 17:01

    $ref_mat1 and $ref_mat2 are references to arrays. In Perl if you want to access a reference to an array you cannot use $reference[$idx] directly -- you have to use the -> operator after the reference like this: $ref_mat1->[0].

    Without it Perl thinks that $ref_mat1[0] refers to an array @ref_mat1 which doesn't exist. Yes, both $var and @var can exist at the same time with differing content, see this example:

    use strict;
    use Data::Dumper;
    
    my $abc = 42;
    my @abc = (1, 2, 3);
    
    print Dumper($abc), Dumper(\@abc);
    
    0 讨论(0)
提交回复
热议问题