in reply to Re: Fighting sub foo($;$$)
in thread Fighting sub foo($;$$)

Why don't you just remove the prototype?

I'd be careful with that, OP says this is legacy code, and simply removing the prototype could change how the code behaves at call sites that the OP doesn't want to affect. The $ prototype doesn't just mean "accept one argument", it also means "force scalar context on this argument".

my @ary = ("a","b","c"); sub foo($;$$) { print Dumper(\@_) } sub foo2 { print Dumper(\@_) } foo (@ary, ("x","y"), "z"); # @_ is [3, 'y', 'z' ] foo2(@ary, ("x","y"), "z"); # @_ is ['a', 'b', 'c', 'x', 'y', 'z']

Replies are listed 'Best First'.
Re^3: Fighting sub foo($;$$)
by LanX (Saint) on Apr 14, 2023 at 21:47 UTC
    I was thinking to add a longer explanation about exactly that, but the OP said it's legacy code she wrote herself.

    And I really doubt she tried to impose scalar context on the arguments, especially when it was always called before the prototype was declared.

    Anyway since she never exported it so far, she can easily check the module for all calls.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery