bioMan has asked for the wisdom of the Perl Monks concerning the following question:
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'.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Prototyping - is it necessary?
by gargle (Chaplain) on Aug 31, 2005 at 18:32 UTC | |
|
Re: Prototyping - is it necessary?
by Thelonius (Priest) on Aug 31, 2005 at 17:59 UTC | |
|
Re: Prototyping - is it necessary?
by Codon (Friar) on Aug 31, 2005 at 22:24 UTC | |
by bioMan (Beadle) on Sep 01, 2005 at 19:49 UTC | |
|
Re: Prototyping - is it necessary?
by jdporter (Paladin) on Aug 31, 2005 at 19:59 UTC | |
by MidLifeXis (Monsignor) on Sep 01, 2005 at 10:51 UTC | |
by bioMan (Beadle) on Sep 01, 2005 at 19:57 UTC | |
by jdporter (Paladin) on Sep 01, 2005 at 21:13 UTC | |
|
Re: Prototyping - is it necessary?
by xdg (Monsignor) on Aug 31, 2005 at 18:01 UTC | |
|
Re: Prototyping - is it necessary?
by polypompholyx (Chaplain) on Aug 31, 2005 at 20:17 UTC | |
|
Re: Prototyping - is it necessary?
by bravenmd (Sexton) on Aug 31, 2005 at 19:48 UTC | |
|
Re: Prototyping - is it necessary?
by geektron (Curate) on Aug 31, 2005 at 18:34 UTC | |
by merlyn (Sage) on Aug 31, 2005 at 18:43 UTC |