627
submitted 10 months ago by jroid8@lemmy.world to c/programmerhumor@lemmy.ml
you are viewing a single comment's thread
view the rest of the comments
[-] palordrolap@kbin.social 7 points 10 months ago* (last edited 10 months ago)

Perl has both $a || $b and $a // $b.

The || version is older and has the value of $b if $a is any false value including undef (which is pretty much Perl's null/nil).

The // version has the value of $b iff $a is undef. Other "false" values carry through.

Ruby took both "no return required" and "no final semicolon required" from Perl (if not a few other things), I think, but it seems that // was Perl later borrowing Ruby's || semantics. Interesting.

i.e. 0 || 1 is 1 in Perl but 0 in Ruby. Perl can 0 // 1 instead if the 0, which is a defined value, needs to pass through.

this post was submitted on 08 Dec 2023
627 points (96.3% liked)

Programmer Humor

32215 readers
104 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS