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

Re: Re: Some suggestions on coding style - a chance to critique

by emilford (Friar)
on Jun 26, 2002 at 15:35 UTC ( #177406=note: print w/ replies, xml ) Need Help??


in reply to Re: Some suggestions on coding style - a chance to critique
in thread Some suggestions on coding style - a chance to critique

Dump the "&" in front of subroutine calls.

What is the reason for this? Does this make some sort of difference?

If you're using a hash, then use the hash:

@$required = split /,/, $$formdata{'required'} unless ($$formdata{ +'required'} eq ""); $$redirect = $$formdata{'redirect'} unless ($$formdata{'required'} + eq ""); . . .
I hate stuff like this. Assigning variables to hash values, IMHO, should only be done if you have some really complex data structures, and even then, I believe you should use some sort of interpolation, lest you continue to de-ref every time you access something

I'm not positive what you're refering to here. Is it just that I should use the hash in my code as opposed to assigning the hash values to a variable and then using the variable instead?

If you're printing to STDOUT in various places, set $|=1; Otherwise, push everything onto an array, and just dump the whole array when you're done

What exactly does the $|=1 do?

Thanks for the suggestions.


Comment on Re: Re: Some suggestions on coding style - a chance to critique
Download Code
Re^3: Some suggestions on coding style - a chance to critique
by Aristotle (Chancellor) on Jun 26, 2002 at 15:51 UTC
    Dump the "&" in front of subroutine calls.
    1. Using & disables a function's prototype.
    2. If you don't pass any parameters to a function, but call it using &, it will receive your current @_ as its parameters. This can lead to very hard to spot errors.
    Is it just that I should use the hash in my code as opposed to assigning the hash values to a variable and then using the variable instead?
    Indeed. Why assign to a hash first when you're going to put it into a variable afterwards? Using a hash also is usually cleaner, since it provides an own little name space for the variables in question; it keeps together what belongs together, and keeps them from littering the global namespace.
    What exactly does the $|=1 do?
    It disables buffering for the currently selected filehandle (which would usually be STDOUT). See perlvar.

    Makeshifts last the longest.

      For a more elaborate discussion of & vs. non-& sub calls, check the replies that followed from one of my early posts, A question of style. Notably, tye's excellent post here.
      "One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2014-07-12 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (238 votes), past polls