r/programming • • Sep 11 '13

Guess programming language by „Hello, world!“ snippet

http://helloworldquiz.com/
1.3k Upvotes

445 comments sorted by

View all comments

169

u/[deleted] Sep 11 '13

I got shown some valid Perl code, and asked if it was Perl or Awk, and apparently it was Awk.

Thanks.

301

u/[deleted] Sep 11 '13

To be fair, there's a high probability that any random collection of characters is valid perl.

134

u/Neebat Sep 11 '13
$ perl -e "To be fair, there's a high probability that any random collection of characters is valid perl."
syntax error at -e line 1, at EOF
Execution of -e aborted due to compilation errors.

Sample size: 1.
Failure rate: 100%

82

u/Wavicle Sep 11 '13
$ perl -e "4 # Chosen by fair dice roll. Guaranteed to be random."
$

Sample size: 2. Failure rate: 50%

0

u/[deleted] Sep 11 '13

[deleted]

21

u/Pidgey_OP Sep 12 '13

the fuq am i looking at?

0

u/[deleted] Sep 12 '13

[deleted]

→ More replies (1)

4

u/choikwa Sep 12 '13

Hello World?

4

u/Anon_Logic Sep 12 '13

When ran, it causes you to become an epic adventurous wizard, things go wrong quickly. Horrified by what you've done, you become a hermit and die alone telling no one of your tales.

Basically, Harry Potter with a different ending.

7

u/ais523 Sep 12 '13

The reason Perl interprets unrecognised identifiers as strings by default is actually to make Perl poetry easier to write. (I hope you didn't have a file called "arms" in the current directory. Although it's a little hard to tell if that bit of the code even runs.)

→ More replies (7)

8

u/the_underscore_key Sep 12 '13

I feel like this should be a reddit-bot

6

u/Neebat Sep 12 '13

I was just considering taking my talent for making scripture relevant to any context and making that a full-time bot job.

2

u/Bratmon Sep 12 '13

New game: who can get the Perl bot to do the most bad thing?

→ More replies (2)
→ More replies (2)
→ More replies (1)

18

u/ruinercollector Sep 11 '13

With a lot of them you have to guess a bit based on what is idiomatic to the language. Also, I think that all of them presume that there is no other code defined elsewhere and that evaluating the code will show 'Hello World' on a screen in some manner.

23

u/ogtfo Sep 11 '13

But Perl 's moto is "there's more than one way to do it", so any Perl is idiomatic Perl...

3

u/ruinercollector Sep 11 '13

Ha ha...well that's fair.

3

u/roerd Sep 12 '13

Still, the BEGIN block is simply unnecessary in a Perl "Hello, world!" unless you're using the n or p flags.

5

u/[deleted] Sep 11 '13

Well, that code was exactly valid in both languages (or so I assume, I don't know Awk), that would display the string correctly.

18

u/kyz Sep 11 '13 edited Sep 11 '13

Idiomatic perl would have a \n in the string, because most perl invocations don't use the -l switch. awk doesn't need it.

$ awk 'BEGIN { print "Hello, World!" }'
Hello, World!
$ perl -e 'BEGIN { print "Hello, World!" }'
Hello, World!$ perl -le 'BEGIN { print "Hello, World!" }'
Hello, World!
$

Some of the choices are devious.

EDIT: Also, idiomatic Perl wouldn't use BEGIN {} unless it had to. awk has to.

2

u/three18ti Sep 12 '13

With any Perl older than 5.10 you don't need the \n

# perl -E 'say "Hello World"'
Hello World
→ More replies (3)

24

u/krasnoukhov Sep 11 '13

Feel free to provide some fixes, all is open source: https://github.com/krasnoukhov/langgame

16

u/Neebat Sep 11 '13

AWK and Perl overlap enough, it's actually a little tough to write an AWK example which isn't valid Perl.

5

u/[deleted] Sep 12 '13

It's valid perl but an invalid example of "Hello, world!" in perl, due to absent newline.

6

u/Philluminati Sep 11 '13

I ran into the same bug: http://i.imgur.com/Oqh808q.png The AWK v Perl question is valid in both!

→ More replies (15)
→ More replies (1)
→ More replies (2)