Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8454731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:06:14+00:00 2026-06-10T12:06:14+00:00

I am trying to write a script for matrix multiplication. Its just a basic

  • 0

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_mat1” requires explicit package name at multiplication.pl line 49.

Global symbol “@ref_mat2” requires explicit package name at multiplication.pl line 49.

Below is my script :

 #!/usr/bin/perl -w
    use strict;

     my @mat1=(
        [2,3,4],
        [1,2,3],
        [3,4,5]
            );

    my @mat2=(
            [2],
            [3],
            [4]
           );


    my ($i, $j, $k);
    my $r_product=[];

   $r_product= mat_multiplication(\@mat1,\@mat2);

    sub mat_multiplication
        {

         my ($ref_mat1,$ref_mat2)=@_;
         my($mat1_row,$mat1_col)=total_rows_column($ref_mat1);
         my($mat2_row,$mat2_col)=total_rows_column($ref_mat2);
             for($i=0;$i<$mat1_row;$i++)
            {
               for($j=0;$j<$mat2_col;$j++)
                {
                   my $sum=0;
                   for($k=0;$k<$mat1_col;$k++)
                    {
                      $sum=$sum+$ref_mat1[$i][$k]*$ref_mat2[$k][$j];
                    }
                    $r_product->[$1][$j]=$sum;
                }
            } 
            return $r_product;

        }


    sub total_rows_column
             { 
              my($r_mat) =@_;
              my $num_row=@{$r_mat};
              my $num_col=@{$r_mat->[0]};
              return($num_row,$num_col);
             }

I searched for this problem and found one link

Explanation of 'global symbol requires explicit package name'

But still not able to resolve it. Please just have a look an let me know where am i doing mistake.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:06:16+00:00Added an answer on June 10, 2026 at 12:06 pm

    $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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write a script that queries the LDAP server and prints out
I'm trying to write a script to make generating Lift projects quicker but I
I am trying to write shell script to read the value from /sys/class/net/eth0/carrier but
I'm trying to write a script for a while now but it seems that
I'm trying to write a script, which would cache images, but am stuck with
I was trying to write a script to execute a C program and measure
I'm trying to write a script for a Black Jack game but have run
I am trying to write a script or a program in Java to find
I am trying to write a script which automatically checks out or updates a
I am trying to write a script for Linux on tcsh. I have not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.