in reply to Re^3: matrices and non-numerical values
in thread matrices and non-numerical values

I revised the code some more according to what makes sense. And I get errors regarding uninitialized values @values and @elements in hash element at each line of the file, list.txt.

use strict; use warnings; open(IN, "list.txt") or die; chomp($line = <IN>); ($element, @abc) = split /\s+/, $line; while (chomp($line = <IN>)) { ($values, @xyz) = split /\s+/, $line; for ($i=0; $i<@xyz; $i++) { $s {$elements}{$values[$i]} = $xyz[$i]; } } close(IN);

Replies are listed 'Best First'.
Re^5: matrices and non-numerical values
by GrandFather (Saint) on Apr 30, 2012 at 02:09 UTC

    You did not run the code you show us or you would have gotten messages that look like:

    lobal symbol "$line" requires explicit package name at noname.pl line +5. Global symbol "$element" requires explicit package name at noname.pl l +ine 6. ...

    Prefix your code with:

    use strict; use warnings; my $fname = 'list.txt'; open my $fOut, '>', $fname or die "Can't create $fname: $!\n"; print $fOut <<TESTDATA; some test data goes here TESTDATA close $fOut; ...

    providing some sensible test data where indicated then show us the result of actually running the code.

    True laziness is hard work