in reply to Re: modify variable on pass by value
in thread modify variable on pass by value

Perl works much better in a flow model, not a do-this-to-that model.
merlyn, while I don't exactly consider myself a slouch as a programmer, I'm not sure what you mean by this. Are you saying it's more efficient to assign the value to something else as opposed to changing a variable in place? Or are you referring to a structured programming thing as opposed to an efficiency issue? Or rather, are you meaning something else entirely?

Inquiring minds want to know...

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just go the the link and check out our stats.

  • Comment on (Ovid) RE(2): modify variable on pass by value

Replies are listed 'Best First'.
RE: (Ovid) RE(2): modify variable on pass by value
by merlyn (Sage) on Sep 11, 2000 at 20:36 UTC
    I'm not talking about efficiency. I'm talking about natural flow in programming. Every time I have to stop to use a foreach loop because a map wouldn't work, I have to create temporary variables, think of reasonable names for them, and then document them, and ensure their scope is large enough but not too large.

    Don't get me wrong. I'm not an FP fascist. But most of the time, temporary values forced on me by the syntax just seems awkward.

    Let's go back to this remove-cap function. In a return-value situation, I can use it like this:

    my @data = map { RemoveCaps $_ } @input;
    Whereas in a act-on-arguments mode, I've got to write this:
    my @data = map { my $x = $_; RemoveCaps $x; $x } @input;
    I can't use $_ directly, because it would attempt to alter @input (see the other thread on that {grin}). So now I have to invent a stand-in, just so I can act on it.

    Just one guy's opinion from someone who's been coding for 30+ years.

    -- Randal L. Schwartz, Perl hacker

      It seems that the author of the question wants symantics that are like chop. People know what chop is going to do to their variable. If the user is well aware of the way the subroutine will work, is it all that bad? Since you would have to do that with chop anyway?

      Just one guy making conversation with someone who's been coding for 30+ years (honest). {grin}

      --
      Casey
      
        Funny you should bring up chop again.

        In the classes I teach, the fact that chop acts on its arguments is one of the most difficult things for students to keep straight. I see people writing all the time:

        $a = chop $a;
        It's precisely because chop is so different from the rest of Perl that people get it wrong. So I'm not in favor of encouraging people to write more things like chop.

        -- Randal L. Schwartz, Perl hacker