in reply to How to return a two dimensional array from a function in Perl?
without changing the old matrix which is passed as an argument to this function.
There's no such thing as a 2d array in Perl. There are arrays whose elements are references to other arrays. That's what my (@graph) = @_; doesn't make a copy of the "2d array". Search for "deep copy"
Other bugs:
Start by using use strict; and use warnings;. They will identify at least two errors.
eq and ne are string comparison operators, but you're using them to compare numbers. Use == and != to compare numbers.
Other tips:
my $i; for ($i = 0; $i < $graph_size; $i++) {
simplies to
for (my $i = 0; $i < $graph_size; $i++) {
and better yet
for my $i (0..$graph_size-1) {
and and or are designed to be used to join statements. Use && and || inside of expressions.
|
|---|