pkm
pkm

Reputation: 2783

perl logical OR operator

#!/usr/bin/perl

$v = "test";
$v |= "best";
print $v;
$v =  "test" | "best";
print $v;

How the OR-ing is coming out here is not clear in second case(first case is oring with null seems to be clear ) ?

Upvotes: 0

Views: 421

Answers (1)

mpapec
mpapec

Reputation: 50637

| is bitwise operator and you wan't to short-circuit string to variable, thus use logical OR ||

$v ||= "best";

Bitwise calculation for first chars "t" | "b" is same as

#             116  | 98        = 118 ("v")
print chr(ord("t") | ord("b"));

Upvotes: 4

Related Questions