http://qs321.pair.com?node_id=189989


in reply to Re: Sub Params as references
in thread Sub Params as references

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. The use of $! in the die statement - the next task is to write a suitable error routine - since this will be a CGI program, and I want a generic fatal error logger to write out a nice HTML page, complete with necessary debugging details for the user to forward to the webmaster.

Thanks again for pointing out my error - one should never try to read perlref late in the evening.

Replies are listed 'Best First'.
Re: Re: Re: Sub Params as references
by rinceWind (Monsignor) on Aug 14, 2002 at 09:51 UTC
    ... I want a generic fatal error logger to write out a nice HTML page, complete with necessary debugging details for the user to forward to the webmaster.
    use CGI::Carp qw(fatalsToBrowser); would be a good starting point for development. This is also probably OK for an Intranet site, but if you put this live on the Internet, you may be exposing yourself too much, see Does fatalsToBrowser give too much information to a cracker?.
Re: Re: Re: Sub Params as references
by demerphq (Chancellor) on Aug 14, 2002 at 11:14 UTC
    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)