Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

equal treatment

by Anonymous Monk
on Oct 26, 2019 at 22:26 UTC ( #11108002=perlmeditation: print w/replies, xml ) Need Help??

I was writing a Perl version of a Python version of a Mac-centric Shell version of a BASIC program when there was a node about unequal treatment and I noticed that my finished perl and the original BASIC were both exactly 23 lines including the comment line added to each program and I could make an interesting node with a cute title that is a direct hyperlink to the source:


# system 'clear'; print "Hello there. I'm a computer. What's your name? "; chomp($_ = <STDIN>); print "Hello ".$_.". You are welcome to computer land."; while () { print "What would you like to do today? 1) Say something random 2) Make a maze 3) Exit Enter your selection "; chomp($_ = <STDIN>); if (/1/) { system 'say', do { @_ = split /\n/, do{local(@ARGV,$/)="/usr/share/dict/words";<>}; $_[int rand@_] } } elsif (/2/) { print rand() < 0.5 ? '/' : '\\' for 1..3000 } elsif (/3/) { print "Bye"; exit } else { print "Try again." } }


# import os import random import sys os.system("clear") print "Hello there. I'm a computer. What's your name?" G = raw_input() print "Hello " + G + ". You are welcome to computer land." while True: print "" print "What would you like to do today?" print "1) Say something random" print "2) Make a maze" print "3) Exit" print "Enter your selection" S = raw_input() if S == "1": F = open("/usr/share/dict/words").readlines() W = random.choice(F) os.system("say {}".format(W)) elif S == "2": for i in range(1, 3000): if random.random()>0.5: sys.stdout.write("/") else: sys.stdout.write("\\") elif S == "3": print "Bye." exit() else: print "Try again."


# clear echo "Hello there. I'm a computer. What's your name?" read G echo "Hello $G. You are welcome to computer land." while true do echo "" echo "What would you like to do today?" echo "1) Say something random" echo "2) Make a maze" echo "3) Exit" echo "Enter your selection" read S if [ "$S" = "1" ]; then echo $( head -n $((7*RANDOM)) /usr/share/dict/words | tail -n 1 ) elif [ "$S" = "2" ]; then for i in {1..3000}; do if (($RANDOM>16384)); then printf '/'; else printf '\'; fi done elif [ "$S" = "3" ]; then echo "Bye." exit else echo "Try again." fi done


REM 5 CLS 7 RANDOMIZE TIMER 10 PRINT "Hello there. I'm a computer. What is your name?" 20 INPUT G$ 30 PRINT "Hello "+G$+". You are welcome to computer land." 40 PRINT "What would you like to do today?" 50 PRINT "1) Make noises" 60 PRINT "2) Make a maze" 70 PRINT "3) Exit" 80 PRINT "Enter your selection:" 100 INPUT S$ 110 IF S$="1" GOTO 200 120 IF S$="2" GOTO 300 130 IF S$="3" GOTO 400 140 PRINT "Try again." 150 GOTO 40 200 SOUND 20+(RND*20000), RND*3 210 GOTO 200 300 SCREEN 1 310 IF RND>.5 THEN PRINT "/"; ELSE PRINT "\"; 320 GOTO 310 400 PRINT "Bye."
Analysis of punctuation in each langage:
cat | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""


cat | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""


cat | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""


cat hello.bas | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""


Last but not least:
use Inline Python => <<'END'; # paste the py code here and run under perl! =) END

I guess replace "say" with "print" ("echo" for shell) if $^O ne 'darwin'

Replies are listed 'Best First'.
Re: equal treatment
by Ea (Chaplain) on Nov 04, 2019 at 14:25 UTC
    Surely, python has a multiline print by now? Doesn't it?

    That'll save 8 punctuation characters which annoy the keepers of the offended-by-punctuation flame.


    Sometimes I can think of 6 impossible LDAP attributes before breakfast.

    Mojoconf was great!

      Python has multiline strings from the beginning (delimited with ''' or """). No string interpolation, though.

      I just noticed OP used interpolation in Shell, but not in Perl, although it would be possible

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://11108002]
Approved by davies
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2020-07-12 03:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found