Modern practice is to make variables as local as possible. Creating a routine to initialize global variables is totally contrary to modern practice. As much as possible, functions/routines should only manipulate data and variables they recieve as arguments. As well, initializing an array to an empty array is pointless, as is initializing a strting to an empty string, or an integer to zero ... they are all created witht he value undef, which in many situations has the effect you assign explicitly. Admittedly, in certain odd situations, it becomes essential to assign a value to avoid pointless warning messages, but assigning routine intial values is a C practice, made obsolete by C++, Java and Perl.
As far as your printarg is concerned, it looks fine to me. However (You knew there was a however coming, didn't you?) the instructions only say to number the args, no comment about starting at zero or one or 17425. I would use that to my advantage to use the automatic numbering system of an array:
for my $idx ( 0..$#_ ) { # $#_ is index of last element, # scalar @_ is number of elements print "$idx $_[$idx]\n"; # or to start numbering at one print $idx+1 . " $_[$idx]\n" }
I was quick to learn $#array, took me a lot longer to learn 'scalar @array .... both are useful.
</code>--
TTTATCGGTCGTTATATAGATGTTTGCA
In reply to Re: Functions in Perl
by TomDLux
in thread Functions in Perl
by bluethundr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |