in reply to Fighting sub foo($;$$)

> Is there any chance that I could tell perl to ignore my past foolishness, and just forget that there is '($:$$)'?

Why don't you just remove the prototype?

use v5.12.0; use warnings; package Somename; use Data::Dump qw/pp dd/; foo(1,2,3,4,5); sub foo { my $one = shift; my $two = shift; my $three = shift; my $four = shift; my $five = shift; pp $four,$five; }

(4, 5)

FWIW: your old code produced a warning that you apparently ignored in the past°

Somename::foo() called too early to check prototype at d:/Perl/pm/foo_prototype.pl line 8.

removing the protoytpe will help you getting rid of this too.

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

°) or you didn't use warnings

Replies are listed 'Best First'.
Re^2: Fighting sub foo($;$$)
by haukex (Archbishop) on Apr 14, 2023 at 20:53 UTC
    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']
      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