On Thu, Mar 26, 2009 at 20:25, <andrewmchor...@cox.net> wrote: > Hello > > I have not had a lot of experience with writing functions in > perl. However I am working on a pretty good size script that > could reduce the code size by writing a function that would > pass in 2 arrays, a file handle and a string. The function > only uses the strings for outputting to the file. All I am > looking for is a simple template. snip
Here is some sample code: #!/usr/bin/perl use strict; use warnings; sub funcname { my ($array1, $array2, $fh, $string) = @_; print $fh "the string is $string\n"; print $fh "\narray1:\n"; for my $i (0 .. $#$array1) { print "\t$i $array1->[$i]\n"; } print "\narray2: ", join(", ", @$array2), "\n"; } my $str = "a string"; my @a1 = qw/zero one two three four/; my @a2 = 1 .. 10; funcname(\...@a1, \...@a2, \*STDOUT, $str); -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/