| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| 2008/9/8 Raul Ruiz Jr. <fast.linux@yahoo.com>: > I am taking an online ceu course in scripting with Unix. I have been stumped by this project. Can anyone out there help me out a bit. I created a script at the bottom and it does not quite work. What am I missing? Hello, Please always 'use strict' at your scripts. This can work: # cat t1.pl use strict; require 'lib.pl'; my @userArray = <STDIN>; my $sum = sumIt(@userArray); print $sum; # cat lib.pl use strict; sub sumIt(){ my @functionArray = @_; my $functionSum; foreach my $line (@functionArray){ $functionSum += $line; } return $functionSum; } 1; # perl t1.pl 1 2 3 4 (ctrl + D) The result is 10. The script t1.pl above reads arguments from STDIN, if you want to read from command line, then change the statement to: my @userArray = @ARGV; Good luck. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.