Re: improving my code: array of references



On Fri, 2007-04-27 at 12:45 -0400, Chas Owens wrote:
On 4/27/07, Pierre Mariani <frenchyp@xxxxxxxxx> wrote:
On Fri, 2007-04-27 at 12:03 -0400, Chas Owens wrote:
On 4/27/07, Pierre Mariani <frenchyp@xxxxxxxxx> wrote:
snip
- modify_variable() doesn't appear to modify anything, otherwise why
are you assigning its return value to the scalar passed as a parameter?
It seems to be just a function.

Modify_variable modifies its input variable.

I think the issue is what you mean by "modifies". In order to say
that the modify_variable function modifies its input then something
like the following must be true:

my $foo = 5
modify_variable($foo)
print "$foo\n"; #prints "6\n"


Yeah, that's exactly it.


Sorry, I realize I replied to fast and was wrong. The way the function
works is:

my $foo = 5;
$foo = modify_variable($foo);
print "$foo\n"; #prints "6\n"

Then why are you doing this

$_ = modify_variable($_)

in all of your examples?
snip
Agree on that, but given other details that I didn't communicate, it is
not quite possible (this is actually a pl/perlu function in postgresql,
the variables I am working on are passed to the function, and their type
is limited by the function definition, so unless I create a composite
type I can't pass them as an array directly).
snip

Perhaps you should describe the full situation then. Without that
information we will not be able to help you very much; we will end up
just shooting in the dark at what we think the problem is.

Thank you, but I got it to work the way I wanted, thanks to Matthew and
Rob's posts:

map { modify_variable(${$_}) } = \($var1, $var2, $var3);

I was continuing the discussion just for the sake of it...

.



Relevant Pages

  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... and answer A modifies the value of x. ... within the class of which the function is a member. ... Base_class is an object of the base class? ...
    (comp.programming)
  • Re: improving my code: array of references
    ... Modify_variable modifies its input variable. ... Either you should be using a array from the beginning, ... are passing by reference. ...
    (perl.beginners)
  • Re: improving my code: array of references
    ... On 4/27/07, Pierre Mariani wrote: ... >>> are you assigning its return value to the scalar passed as a parameter? ... > I think the issue is what you mean by "modifies". ...
    (perl.beginners)
  • Re: XmlDocument.SelectNodes()
    ... static private XmlNode checkEgsistance ... why is that a "ref" parameter? ... which modifies the value of the variable (as opposed to the object it ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Debuggers
    ... normal parts of language that makes a human language easier to ... without noticing that it was Foo and not foo what should have been ... web which bear on this topic of debugging software. ...
    (comp.lang.c)