Once upon a midnight dreary, while "I pondered", !weak and weary;
Over many a quaint and curious volume of for@gotten, @lore;
While I nodded, nearly napping, until /|there came a tapping|/;
As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;
"Tis some visitor", I-muttered, "tapping at my chamber door";
print unpack f, ${!this} and nothing x more
Try it online!
Ah, distinctly I remember it was in the bleak December;
And each separate dying ember wrought its ghost upon the floor.
Explanation / Spoiler:
Perl has a feature called 'barewords', which allows alphanumeric sequences to automatically be parsed as strings. This means that something like
foo bar baz
Will parse as valid Perl, but give a runtime error. However, if we can avoid Perl evaluating it, we can avoid the runtime error. The following program will run without any error:
foo bar baz while 0
Now let's have a look line by line:
Once upon a midnight dreary, while "I pondered", !weak and weary;
"I pondered", !weak and weary
evaluates essentially to ("I pondered", false)
which is falsy so the stuff on the left hand side of the while loop does not get evaluated.
Over many a quaint and curious volume of for@gotten, @lore;
This is a for
loop over the lists @gotten
and @lore
, which are empty, so the left hand side doesn't get evaluated.
While I nodded, nearly napping, until /|there came a tapping|/;
This is an until
loop, where /|there came a tapping|/
is a regex matching against $_
. Even though $_
is empty, the leading |
matches against the empty string so the match becomes truthy so we don't evaluate the left hand side.
As if someone ? ${!gently} = "rapping" ^ "rapOing at": my $chamber, $door;
if
is a keyword here. someone
is a bareword which is truthy, so we evaluate ${!gently} = "rapping" ^ "rapOing at"
, which sets ${''}
to the string "\0\0\0?\0\0\0 at"
. my $chamber, $door
parses as a function call which is never evaluated, so there's no error.
"Tis some visitor", I-muttered, "tapping at my chamber door";
I
and muttered
are both barewords.
print unpack f, ${!this} and nothing x more
This parses as (print unpack f, ${!this}) and nothing x more
. ${!this}
is ${''}
, which is our string from earlier. unpack f
is a function that unpacks a single 32 bit float from a packed 4 byte representation. The first 4 bytes of ${''}
are "\0\0\0?"
, which happens to be a valid representation of 0.5
. The rest of the string is ignored.
Since (print unpack f, ${!this})
is truthy, the right hand side of the and
is evaluated. x
is the string repeat operator, and nothing
and more
are both barewords, so there's no error generated.