Håkon Hægland
Håkon Hægland

Reputation: 40778

Using Data::Printer with qx operator

I was experimenting with the Data::Printer module, and it worked fine until I tried to print the return value of a system call using qx operator:

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

p qx/echo -n Hello/;

This gives me the following error:

Type of arg 1 to Data::Printer::p must be one of [@$%&] (not scalar)

I assume this error occurs because qx is not recognized as a scalar, hash, array, or function. So I tried:

p my $temp = qx/echo -n Hello/;

and it worked fine. The question is, if it is possible to avoid the use of the $temp variable? (I think this syntax would become annoying to use and remember in the long run)

Upvotes: 0

Views: 51

Answers (1)

Borodin
Borodin

Reputation: 126742

Unlike Data::Dumper and Data::Dump, the default mode of Data::Printer allows you to display only the contents of variables, not arbitrary expressions

This behaviour can be circumvented by disabling the use_prototypes option in the use statement, when arrays and hashes must be passed explicitly by reference

use Data::Printer use_prototypes => 0, output => 'stdout';

p qx/echo -n Hello/;

output

"Hello"

Upvotes: 1

Related Questions