in reply to The Backslash Challenge
Are you sure you don't want to try yourself?
Double spoilers don't work correctly on PerlMonks, but they hide the contents twice. Give it a few more minutes.
1.
qq\@{[chr 92]}\
There are infinitely many ways how to get a backslash. We can use pack
2.
qq\@{[pack "c", 92]}\
or sprintf
3.
qq\@{[sprintf '%c', 92]}\
Another way is to use a bitwise operation, e.g. xor. Here are just two examples I liked:
4.
qq\@{['{'^"'"]}\ qq\@{['~'^'"']}\
Then I skimmed perlfunc searching for functions that can return a backslash. I found a few that return a bit more so we need to combine them with substr or a match:
5.
qq\@{[substr quotemeta ";", 0, 1]}\ qq\@{[prototype("CORE::push") =~ /^(.)/]}\
We can also require a core module that outputs a backslash.
6.
qq\@{[require File::Spec::Win32 and File::Spec::Win32->rootdir]}\ qq\@{[do{require Data::Dumper;substr Data::Dumper::Dumper("'"),-5,1}]} +\
OK. Is there any other way than using the array dereference? I've found a way! Let's use a string dereference instead. We need to create a string reference inside, which I can't do without a backslash, but fortunately there's eval that makes it possible to generate the backslash without using a backslash.
7.
qq\${eval chr(92).'"'.(chr(92)x2).'"'}\
Finally, here's a joke. What a pity it doesn't work. Update: In a way, it does! See Tux's reply below!
∞.
qq\@{[reverse "/"]}\
To sum it up:
print qq\@{[chr 92]}\, qq\@{[pack "c", 92]}\, qq\@{[sprintf '%c', 92]}\, qq\@{['{'^"'"]}\, qq\@{['~'^'"']}\, qq\@{[substr quotemeta ";", 0, 1]}\, qq\@{[prototype("CORE::push") =~ /^(.)/]}\, qq\@{[require File::Spec::Win32 and File::Spec::Win32->rootdir]}\, qq\@{[do{require Data::Dumper;substr Data::Dumper::Dumper("'"),-5,1}]} +\, qq\${eval chr(92).'"'.(chr(92)x2).'"'}\, qq\@{[reverse "/"]}\;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: The Backslash Challenge
by Tux (Canon) on Mar 25, 2021 at 11:03 UTC |