Vicky
Vicky

Reputation: 1328

What is \0 (a number prefixed with a backslash) in Perl?

I saw a piece of code in Perl as below:

my $SUCCESS = \0;
my $FAILURE = \1;

It is an assignment and I cannot understand the significance of \1 and \0.

Upvotes: 2

Views: 436

Answers (2)

jmcneirney
jmcneirney

Reputation: 1384

\1 creates a reference to a scalar. Print $SUCCESS and you'll see SCALAR(0xb83938) or something similar. In order to get the value try printing $$SUCCESS and you should get the value of the variable.

Upvotes: 3

daxim
daxim

Reputation: 39158

These two specific values are special cases in the JSON family of modules, and serialise to false and true.

Upvotes: 5

Related Questions