madM has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks!
i wrote a subroutine to print a matrix and now im trying to pass the arguments of the subroutine with getopt::long hereīs what i wrote: so i want to pass the matrix $A, $forprint and $header with options .. but i dont know exactly how.. any suggestions?
sub printMatrix1 { my ($A,$forprint,$header1) = @_; #$A is the matrix to be printed, +$forprint is the format and $header1 is the header of the matrix to b +e printed open(OUT,">$header1.txt") or die "The File $header1.txt couldnīt b +e opened\n"; print OUT "$header1\n\n"; print OUT ' '; #prints space first so + that upper letters stay formated in place my $format2= $forprint; substr ($format2,length($format2)-1,1,'s'); #### for printing uppe +r letters in the matrix foreach my $key (@aminos){ #Prints Upper aminoacido lette +rs of the Matrix printf OUT ("$format2 ", $key); } print OUT "\n"; foreach my $key (@aminos) { print OUT $key,' '; foreach my $key2 (@aminos ) { printf OUT ("$forprint " , $A->{$key}->{$key2}); } print OUT "\n"; } close OUT; }

Replies are listed 'Best First'.
Re: updating code with getopt::long
by toolic (Bishop) on Mar 19, 2014 at 15:36 UTC
    Getopt::Long is used to parse the command-line. It is not used for passing arguments to a sub.

    You could pass another argument to your sub, such as a reference to a hash of options.