I am playing around with modules, and have created a very simple test module. However, it has a bug.
package bioMan; use strict; use warnings; sub getFileData(){ #variables my @data = (); (my $datafile, $chomp) = @_; open FH, $datafile or die "Can't open $datafile: $!\n"; @data = <FH>; chomp(@data) if $chomp; close FH or die "Can't close $datafile: $!\n"; wantarray ? return @data : return(join '', @data); } 1;
I am running ActivePerl 5.8.7 on Win2000. When I used the above package in a short test program with the statement:
@seqarray = bioMan::getFileData($in, 1);
I got a "too many arguments" error that was rectified by modifying line 6 of the package to:
sub getFileData($$){
I didn't think prototyping was necessary. Am I wrong?
I want $chomp to be an optional parameter with a default value of undef, but prototyping forces me to explicitly include a value for $chomp whenever I call getFileData.
Retitled by g0n from 'prototyping'.
In reply to Prototyping - is it necessary? by bioMan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |