Zaid Zaid - 4 months ago 19
Perl Question

Does Data::Printer handle array slices?

Apparently not:

use strict;
use warnings;
use Data::Printer;

my @values = 1 .. 99;
p @values[0..9];



The documentation doesn't shed any light on the matter as far as I can tell.


  • Why doesn't the code above work?

  • Is it possible to make it work without resorting to a temp?

mob mob

The prototype on Data::Printer::p is \[@$%&];%, so it will accept a named array but not an arbitrary list or anonymous array reference.

There is a Data::Printer::p_without_prototypes function that will accept this input, and if you import Data::Printer with

use Data::Printer use_prototypes => 0;

then p in the current package will refer to this function, and accept your input.

use Data::Printer use_prototypes => 0;
my @values = 1 .. 99;
p [@values[0..9]];