in reply to How can I avoid code repetition here

Your code will not work if $_ is lexical. And I don't know whether that can be fixed. At first I thought you could solve it with a prototype:
sub lchompx (;$_)
(swapping the arguments if two arguments are given). But will it gives you access to a lexical $_ is called with one argument, it won't pass $_ if not called with any arguments. A prototype of _;$ will fail to do right thing if one argument is given.

Replies are listed 'Best First'.
Re^2: How can I avoid code repetition here
by rovf (Priest) on Oct 08, 2009 at 09:35 UTC
    Your code will not work if $_ is lexical.
    You can't make $_ a lexical:

    $ perl -lwe "my $_='abc'; chop; print" Can't use global $_ in "my" at -e line 1, near "my $_" Execution of -e aborted due to compilation errors.

    -- 
    Ronald Fischer <ynnor@mm.st>
      You have been able to do that for the past 22 months:
      $ perl -wle 'my $_ = "abc"; chop; print' ab $
        Which Perl version was this introduce in? I still used 5.8.8, so it was illegal there. I see that it works in 5.10

        -- 
        Ronald Fischer <ynnor@mm.st>