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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.