in reply to Re^4: How can I avoid code repetition here
in thread How can I avoid code repetition here

5.10. Which was released about 22 months ago. You shouldn't be claiming things are not allowed if all you do is check it against an old version of Perl.
  • Comment on Re^5: How can I avoid code repetition here

Replies are listed 'Best First'.
Re^6: How can I avoid code repetition here
by rovf (Priest) on Oct 08, 2009 at 14:24 UTC

    Honestly I had not expected that this would ever become valid, and I'm still puzzled how this can work, i.e. how a builtin function (like chop) can modify *any* localized variable by name...

    -- 
    Ronald Fischer <ynnor@mm.st>
      All what's happening is an implicite passing of $_. But passing $_ isn't any different from passing $str. And you do believe that my $str = "..."; chop $str modifies the lexical (I guess you meant lexical variable where you write localized variable) variable, don't you?
        you do believe that my $str = "..."; chop $str modifies the lexical

        Yes, with *explicit* passing of a lexical, it is easy to understand how it is done; and if the compiler "knows" about chop (as a 'builtin' function), I can understand now how this work for this case. I wonder whether it would also be possible to write a user defined sub which, when called without parameters, acts on $_ even if it was lexically declared. I don't see how this can be done...

        -- 
        Ronald Fischer <ynnor@mm.st>