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

  • SEARCH
  • Home
  • 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 7547149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:22:47+00:00 2026-05-30T09:22:47+00:00

I wrote the following Perl function sub Outputing { my $featureMatrix = shift; my

  • 0

I wrote the following Perl function

  sub Outputing
  { 
     my $featureMatrix = shift;
     my $indexRow = shift;
     my $fileName = "/projectworkspace/input.dat";

     open(DATA, "> $fileName");
     printf DATA "%d", $#$indexRow;
     print DATA "\n";

     my $numDataPoints = $#{$featureMatrix{$indexRow->[1]}};
     printf DATA "%d", $numDataPoints;
     print DATA "\n";

     close DATA;    
    }

I calling Outputing as follows:

Outputing($matrix, $Rows);e

$matrix is a hash of array, whose structure is like this

   my $matrix 
     = { 200 => [ 0.023, 0.035, 0.026 ], 
          110 => [ 0.012, 0.020, 0,033], 
        }; 

Rows is an array storing the sorted key of matrix, it is obtained as follows

my @Rows = sort keys %matrix;

both matrix and Rows are used as parameters passed to Outputing.

The printed out $numDataPoints is -1, which is not correct? I do not know which might be the reason that causes this problem? If we use the above example, and assume $indexRow->[1]=110, then $numDataPoints should be 2. I am not sure whether the $#{$featureMatrix{$indexRow->[1]}}; is the correct way to get the size of this array.

  • 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-05-30T09:22:48+00:00Added an answer on May 30, 2026 at 9:22 am

    Assuming that you’ve included all the relevant code, this:

    my @indexRow = sort keys %featureMatrix;
    

    should be this:

    my @indexRow = sort keys %$featureMatrix;
    

    and this:

         my $numDataPoints = $#{$featureMatrix{$indexRow->[1]}};
    

    should be this:

         my $numDataPoints = $#{$featureMatrix->{$indexRow->[1]}};
    

    That is, the problem is that in some places, you’re using a hash named %featureMatrix, and in others, you’re using a hashref named $featureMatrix that refers to an anonymous hash.

    You should be using use warnings and use strict to prevent such mistakes: those would have prevented you from using %featureMatrix when you’ve only declared $featureMatrix. (Actually, use warnings might not help in this case — it could detect if you used %featureMatrix exactly once, but in your case, you use it a few times — but use strict would almost certainly have helped.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting problem. I wrote the following perl script to recursively loop
I wrote the following: Object.prototype.length = function(){ var count = -1; for(var i in
please look at the following code first. #! /usr/bin/perl package foo; sub new {
I have a quite simple perl script, that in one function does the following:
I wrote the following Perl script (below) in order to create simple XML file.
In order to list pathes in Windows,I wrote below Perl function(executed under StrawBerry runtime
I wrote a Perl program to capture a live data stream from a tail
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject

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.