Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Functions in Perl

by TomDLux (Vicar)
on May 23, 2004 at 04:20 UTC ( [id://355687]=note: print w/replies, xml ) Need Help??


in reply to Functions in Perl

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://355687]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (7)
As of 2024-04-18 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found