sekenre,
@sekenre@fosstodon.org avatar

I have also been known to program in

Here's a puzzle for y'all:

What does this code block print?

chrisjrob,

@sekenre I'd expect it to print:
func array foo hash bar baz foo bar
The fact you say it is a puzzle makes me doubt myself...!

sekenre,
@sekenre@fosstodon.org avatar

@chrisjrob I was teaching my co-workers some perl and we came up with this example of maximum sigil/variable name confusion. So it's more of a puzzle if you've never seen perl before.

sekenre,
@sekenre@fosstodon.org avatar

@chrisjrob I still have no idea how the perl interpreter resolves these situations.

yzh,
@yzh@fosstodon.org avatar

@sekenre @chrisjrob I'm not an expert at all in how the Perl interpreter works, but I do work with Perl a lot. I think the sigils are what makes what's going on in code like that pretty much unambiguous. One of the reasons I like Perl, and the use of sigils, a lot.

I think if you understand enough Perl, and how the sigils change to indicate the type of data, you'll think it's pretty straightforward.

sekenre,
@sekenre@fosstodon.org avatar

@yzh @chrisjrob Yep. My students, (python devs all) were playing "what if?" and we came up with a toy example.

barubary,

@sekenre @chrisjrob I feel like you could eke out more confusion by adding references to the mix.

sub bork { "bork", "copper" }<br></br>my $bork = [["simple", "day"], "frog"];<br></br>my @bork = (["banana", "apple"], ("sweet", "cloud"));<br></br>my %bork = (<br></br>    "enigma" => 42,<br></br>    "copper" => "red",<br></br>    "bork"   => "doge",<br></br>    "sweet"  => "corn",<br></br>    "cloud"  => "strife",<br></br>);<br></br>print "1. ", join(" ", $bork, bork, $bork{ bork }, $bork{+bork }, $bork{(bork)}), "n";<br></br>print "2. ", join(" ", $bork[1], $bork->[1], $$bork[1]), "n";<br></br>print "3. ", join(" ", $bork[0][1], $bork[0]->[1], $bork->[0][1], $bork->[0]->[1], $$bork[0][1], $$bork[0]->[1], ${$bork}[0][1], ${$bork[0]}[1], ${$bork->[0]}[1]), "n";<br></br>print "4. ", join(" ", @bork, @$bork, @$bork[1], @{$bork[0]}, @bork{bork}, @bork{@bork}, @bork{bork, "bork"}), "n";<br></br>

PS: No, I've never seen anything like this in real-world code.
PPS: Ignore the warnings. 🙂

sekenre,
@sekenre@fosstodon.org avatar

@barubary @chrisjrob @bork omg. I love it! 🙏

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • DreamBathrooms
  • ngwrru68w68
  • tester
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • InstantRegret
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • mdbf
  • tacticalgear
  • JUstTest
  • osvaldo12
  • normalnudes
  • cubers
  • cisconetworking
  • everett
  • GTA5RPClips
  • ethstaker
  • Leos
  • provamag3
  • anitta
  • modclub
  • megavids
  • lostlight
  • All magazines