Did you read the perldoc (at your command prompt, "perldoc -f avg") for the function avg to learn how to use it correctly?
No? You didn't bother.... or couldn't read it?
Well, if the latter, that's because there is no such function, nor is there a (CPAN) module of that name to be "use"ed (which you didn't do, in any case).
As a wise one once said, 'You can't just make s*#t up and expect the computer to understand.'
And surely your attempt to run that code produced more than some (unspecified -- bad; direct, verbatim quotes -- good!) hints that it (sic) "dosen't like the $file and @file comments." ... perhaps something like this:
String found where operator expected at eraseme.pl line 6, near "open
+FILE3, ""
(Might be a runaway multi-line "" string starting on line 5)
(Missing semicolon on previous line?)
String found where operator expected at eraseme.pl line 24, near "open
+ (OUTFILE, ""
(Might be a runaway multi-line "" string starting on line 6)
(Missing semicolon on previous line?)
String found where operator expected at eraseme.pl line 24, near "txt"
+) or die(Output file error""
syntax error at eraseme.pl line 6, near "open FILE3, ""
Global symbol "@file1" requires explicit package name at eraseme.pl li
+ne 26.
Global symbol "@file2" requires explicit package name at eraseme.pl li
+ne 26.
Global symbol "@file3" requires explicit package name at eraseme.pl li
+ne 26.
eraseme.pl had compilation errors.
And you'll notice the test gave up before it even got to the nonsense on line 26 and without mentioning a problem with the non-existent "spilt.
So here are a few more pointers toward code "correctness":
- Learn how to read error and warning messages; that is, to understand them.
- Make sure you actually know how the functions you use actually work.
- To reach that point, take some babysteps first: in this case, you might want to work out some code to calculate as average, given a set of three $vars instantiated with decimal values. Test with per -c scriptname.pl and when that comes up clean, see if what you've written actually works correctly. Then write a script or two opening files and reading from them to scalars, arrays and/or hashes; next re-read the doc for spilt (or split, as the case may be).
Now, combine them, and see if you did so correctly (ie, have error- and warning-free, working code)
- Learn the basics of the debugger. That's a tool that will help you a lot. But also read a few posts here about using print statements as a debugging tool.
Some will view these comments as "harsh." Perhaps, but programming is a harsh art requiring the discipline to learn your tools... and the willingness to learn how to learn. Unlike the proverbial 'horseshoes and handgrenades, "close" is NOT good enough."
If you can avoid reading a nonexistant intent to offend into this post, you'll discover motifs and methods that will ease your progress toward mastery.
|