So, I'm trying to make a script that will assign input to a variable vector, print, and go to the next line and repeat. Go figure, I'm stuck. Any ideas?
#!/usr/bin/perl use strict; use warnings; use diagnostics; use Math::Vector::Real; my $source = "./IN"; my $out = "./OUT"; open(IN, '<', $source) or die "Couldn't open $source: $!\n"; open(OUT, '>', $out) or die "Couldn't open $out: $!\n"; sub vector { my ($aa) = @_; $aa->[0] = my $one; $aa->[1] = my $two; $aa->[2] = my $three; my $vector = V($one, $two, $three); } my @data = map [ split ], grep /\S/, <IN>; foreach my $d1 (@data) { print OUT " The vector of Atom ($d1->[0], $d1 +->[1], $d1->[2])is : %f\n", vector($d1); } close IN; close OUT;
My Input file is:
0 5 5 1 2 3 3 5 6 2 5 2 5 5 5 5 5 6
And this is the error I get when I run it,
mac95406:perl a7c$ ./perl Use of uninitialized value in join or string at /Library/Perl/5.16/Math/Vector/Real.pm line 219, <IN> line 6 (#1) (W uninitialized) An undefined value was used as if it were alread +y defined. It was interpreted as a "" or a 0, but maybe it was a mi +stake. To suppress this warning assign a defined value to your variables. To help you figure out what was undefined, perl will try to tell y +ou the name of the variable (if any) that was undefined. In some cas +es it cannot do this, so it also tells you what operation you used th +e undefined value in. Note, however, that perl optimizes your progr +am anid the operation displayed in the warning may not necessarily ap +pear literally in your program. For example, "that $foo" is usually optimized into "that " . $foo, and the warning will refer to the concatenation (.) operator, even though there is no . in your program.
The line that the error directs me to is:
sub as_string { "{" . join(", ", @{$_[0]}). "}" }
Even knowing what that error means would be great for starters. Everything I see is declared and should have a value. I'm probably just blind though. Any help is appreciated.

In reply to How to vector by jcklasseter

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.