in reply to weird error message in middle-aged-perl(5.14)

Lvalue subroutines should have a single point of return – and not use the return keyword. So something like

my @x; sub foo :lvalue { my ($cond, $i) = @_; if ($cond) { return $x[$i]; } else { return $x[0]; } }

should instead be written as

my @x; sub foo :lvalue { my ($cond, $i) = @_; my $lvalue; if ($cond) { $lvalue = \$x[$i]; } else { $lvalue = \$x[0]; } $$lvalue; }

which is a general solution, or

my @x; sub foo :lvalue { my ($cond, $i) = @_; my $lvalue; ($cond) ? $x[$i] : $x[0]; }

Edit: further notes I see you are using the mem module, which is basically useless. If you need to perform an assignment at compile time, just use a BEGIN block:

our @fields; BEGIN { @fields=qw(one two three) }

While this is a little more verbose, you now don't need any non-standard modules. A similar rationale applies to the P package. It attempts to be very DWIM-y, but I find it's design distasteful. Here, explicitly using the builtin printf rather than the P function would have been clearer.

When posting minimal code snippets for others to reproduce a problem, then it's customary to remove such irrelevant dependencies – I don't shove my similar Util::Underscore in everyone's face.

Replies are listed 'Best First'.
Re^2: weird error message in middle-aged-perl(5.14)
by perl-diddler (Chaplain) on May 09, 2014 at 15:17 UTC
    You misunderstand. If you require me to rewrite the code I'm am having a problem with in order for you to be able to help, then realize, that I don't want your help. It's too costly.

    Just like I used "..." to skip sections not important, I use shorthand in my examples that allow me to focus on the problems, not superfluous code. "P" is like "..." it's a generic print operator that embodies the spirit of perl's DWIM philosophy -- something you find distasteful. Why use perl if you find it's core philosophy distasteful.

    Also, I would wager it's not P's design that is distasteful, but it's feature set. Since, if I asked you how you would design it, you'd say you wouldn't -- meaning it's not a matter of design, but a matter of it's functionality.

    How can functionality that embodies perl print operators be distasteful?