Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Your first comment - at least one of the strings can get rather large - hence the desire to avoid local copies and all the associated memory wastage.

Hmm, i could be completely wrong, (but i dont think so), but perl strings are never passed by value. Perl strings arent like base string types in most languages. They live inside of an SV, which contains a pointer to the block of memory holding the string along with a bunch of housekeeping information. And since only SV's are passed around on the stack your string isnt going to be copied. The usualy recommendations about passing hashes and lists by reference have to do with the way perl listifies these types when used as parameter arguments. Thus by passing a reference to the array you only pass one SV, but by passing a listified array you pass one SV for every element.

Also, again I could be wrong about this, but I think perl variables are always passed by reference (actually not reference in the normal sense but a special kind of reference called an alias). This means that by modifying the contents of @_ directly you actually end up modifying the original value. This suggest to me quite strongly that perl variables are always passed "by reference".

Yves / DeMerphq
---
Software Engineering is Programming when you can't. -- E. W. Dijkstra (RIP)


In reply to Re: Re: Re: Sub Params as references by demerphq
in thread Sub Params as references by Maclir

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 lurking in the Monastery: (3)
As of 2024-04-25 20:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found