0

I have a table in an array and I am trying to sort it using the following method:

@table_array = sort { $a->[0] <=> $b->[0] } @table_array;

But I get this error:

Can't use string ("5") as an ARRAY ref while "strict refs" in use at 

My $table_array[x][0] is a numeric value. I create this table by reading two files and merging them on a common field ($table_array[x][1] to be exact).

I am not able to understand where I have asked the elements to be accessed using string references.

Thanks, Karthick S.

1
  • See sort Commented Mar 2, 2013 at 17:37

1 Answer 1

3

My $table_array[x][0] is a numeric value.

No, that's not true. For one of the elements, $table_array[x] is 5 instead of a reference.

>perl -e"use strict; $a=5; $a->[0]"
Can't use string ("5") as an ARRAY ref while "strict refs" in use at -e line 1.

Maybe you did

$table_array[$x] = @rec;

instead of

$table_array[$x] = \@rec;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.