Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I thought that I would have to pass a reference to the scalar in order to modify them (i.e. - \$variable). Is this not true?
You don't *have* to pass by reference to modify variables as @_ is just a list of aliases (it's magic you see) e.g
sub foo { $_[0] = "modified in foo()"; print "in foo()\n"; } my $var = "a string"; print "\$var is $var\n"; foo($var); print "\$var is $var\n"; __output__ $var is a string in foo() $var is modified in foo()
However passing by reference is more explicit, but that then introduces in the issue of 'dirtying' your arguments which is generally agreed to be avoided if possible. I believe the reasoning is that entering a function shouldn't modify the state of your program, although this can usually be ignored with more complex data e.g throwing around hashes is potentially pricey.
I could push everything into a seperate data type, but wouldn't that make things a little less clear and require "not necessary" lines of code?
At the worst it will require a line or two of code, but organising your data is far more likely to *reduce* your code. Let's take send_mail() for example. Currently you have 8 arguments, whereas I'd probably reduce that to 2 arguments with all the sendmail-related information in a hash or even a hash of hashes. But then again I think that all this throwing about of data is a symptom of a mis-organised program, to which I think part of the solution would be re-structuring the data as once you have well-defined data structures the program tends to follow.
HTH

_________
broquaint


In reply to Re: Re: Re: Some suggestions on coding style - a chance to critique by broquaint
in thread Some suggestions on coding style - a chance to critique by emilford

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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-03-28 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found