Posts by Anonymous Monk
equal treatment in Meditations
1 direct reply — Read more / Contribute
by Anonymous Monk
on Oct 26, 2019 at 18:26

    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:

    Perl

    # https://www.perlmonks.org/index.pl?node=equal+treatment 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." } }

    Python

    # https://news.ycombinator.com/item?id=20127987 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."

    Shell

    # https://news.ycombinator.com/item?id=20123365 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

    BASIC

    REM https://news.ycombinator.com/item?id=20118639 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 hello.pl | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""
    
    '';".'.'?";($_=<>);"".$_."..";(){"?)))";($_=<>);(//){'',{@_=/\/,{(@,$/)="////";<>};$_[@_]}}(//){()<.?'/':'\\'..}(//){"";}{"."}}
    
    
    cat hello.py | perl -ne '$_=join"",<STDIN>;@_=$_=~/[^A-Za-z0-9\s]/g;print@_'; echo""
    
    .("")".'.'?"=_()""++"..":"""?"")"")"")"""=_()=="":=("////").()=.().("{}".())=="":(,):.()>.:..("/"):..("\\")=="":"."():"."
    
    cat hello.sh | 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'

The missing link between "you may need to install the module" and "distribution installed" application is running! in Meditations
4 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 24, 2019 at 07:57
    You may try a perl app and see Can't locate Foo/Bar.pm in @INC (you may need to install the Foo::Bar module) (@INC contains: ...

    So you install the Foo::Bar module and try again and see Can't locate Bar/Baz.pm in @INC (you may need to install the Bar::Baz module) (@INC contains: ...

    So you install the Bar::Baz module and the application runs.

    Module::Load::Conditional (core) can reduce the pain to:

    Install required modules Foo::Bar Bar::Baz from CPAN? (y)/n y
    Use 1. cpan or 2. cpanm 1/(2) 2
    Successfully installed Foo::Bar
    Successfully installed Bar::Baz
    
    Or select 'n' for something more than @INC:
    Install required perl modules:
    cpan Foo::Bar Bar::Baz 
    cpanm -v Foo::Bar Bar::Baz 
    
    Can't locate Foo::Bar Bar::Baz in @INC (@INC contains: ...
    
    Should perl be doing something like this on the core level?

    Should monks adopt this mess or fold it into a module so it becomes a best practice?

    How could this idea be improved?

    Thank you!

    #!/usr/bin/perl use strict; use warnings; #use Foo::Bar; #use Bar::Baz; use Module::Load::Conditional 'can_load'; BEGIN { my $modules = [ map {$_} qw[ IPC::Cmd Foo::Bar Bar::Baz ]]; my @install = do { local @_; for my $m (@$modules) { push @_, $m unless can_load(modules => {$m,undef}, autoload => 1)} @_ }; @install and do { print 'Install required modules ', join(' ', @install), ' from CPAN? (y)/n '; my $in = <STDIN>; chomp $in; $in ||= 'y'; my $cpanm = IPC::Cmd::can_run('cpanm'); if (lc $in eq 'y') { if ($cpanm) { print 'Use 1. cpan or 2. cpanm 1/(2) '; my $cpan = do { local $_ = <STDIN>; chomp $_; $_ ||= 2; $_ = 2 unless /^1|2$/; $_ }; if ($cpan == 2) { unless (system $cpanm, '-v', @install) { system 'perl', $0, @ARGV; exit } } } unless (system 'cpan', @install) { system 'perl', $0, @ARGV; exit } } else{ die "Install required perl modules:\n". join ' ', 'cpan', @install, "\n". ($cpanm ? join(' ', 'cpanm', @install) : '')."\n\n". "Can't locate ".join(' ',@install).' in @INC '. '(@INC contains: '.join(' ', @INC).") \n" } }; Bar::Baz->import('Something')}
use all core modules, pragmas and extensions in Meditations
1 direct reply — Read more / Contribute
by Anonymous Monk
on Oct 23, 2019 at 10:55
    I wondered what would happen if one were to use all core modules. Here's what happened:

    19 core libs can not be simply used, without being fatal, so they're commented out (ymmv on versions ne 5.26.2).

    The perl interpreter grows to about 150 megabytes.

    A series of warnings is printed which may or may not have any value. This is why I'm sharing it here. In case the warnings indicate real issues, or interesting things to investigate.

    This 1-liner generates the ~650 line script, redirects stdout to the file "useallcore" and runs "perl useallcore" which prints the errors, and lines from ps about the perl process.

    perl -MExtUtils::Installed -MModule::Metadata -e '$not=q/_charnames|au +touse|blib|charnames|Devel::Peek|encoding|encoding::warnings|feature| +File::Spec::VMS|filetest|GDBM_File|if|O|ok|open|Pod::Simple::Debug|so +rt|Thread|threads/;$not={map{$_=>1}split/\|/,$not};print"#!/usr/bin/p +erl\n# Load all core Perl modules, pragmas and extensions\n# Exceptio +ns, to prevent errors:\n".(join "\n", map {"#$_"} sort {lc$a cmp lc$b +} keys %$not).")\n\n";@_=grep/\.pm/,(ExtUtils::Installed->files("Perl +"));for(@_){$m=Module::Metadata->new_from_file($_)->{module} or next; +push@m,$m}for(sort{lc$a cmp lc$b}@m){print $not->{$_}?"#":"","use $_; +\n"}print"\nprint `ps -v | grep \"\$\$\"`;\n"' > useallcore; perl use +allcore
Are the words "strict" and "warnings" too negative? in Meditations
5 direct replies — Read more / Contribute
by Anonymous Monk
on Sep 03, 2019 at 15:56
    #!/usr/bin/perl # # Q: Are the words "strict" and "warnings" too negative? # A: Synonyms from Moby Thesaurus II @ http://www.dict.org use strict; use warnings; my @strict = strict(); my @warnings = warnings(); while () { print $strict[int(rand(@strict))], ' ', $warnings[int(rand(@warnings))], "\n"; sleep 2 } sub strict { return split /,\s+/, qq/Sabbatarian, Spartan, Spartanic, absolute, absolutist, absolutistic, accurate, arbitrary, aristocratic, arrogant, aspersion, astringent, attentive, austere, authoritarian, authoritative, autocratic, bigoted, bossy, careful, censorious, choicy, choosy, circumscription, close, cold-blooded, complete, compulsive, confining, conscientious, constant, constrictive, correct, cramp, creedbound, critical, defined, delicate, demanding, despotic, detailed, dictatorial, direct, discriminating, discriminative, dogmatic, domineering, dour, draconian, evangelical, even, exact, exacting, exigent, express, exquisite, faithful, fastidious, feudal, fine, finical, finicking, finicky, firm, forbidding, fundamentalist, fussy, grim, grinding, hard, hard-boiled, harsh, hidebound, high-handed, hyperorthodox, imperative, imperial, imperious, inerrable, inerrant, infallible, inflexible, ironhanded, just, limitation, literalist, literalistic, lordly, magisterial, magistral, masterful, mathematical, meticulous, micrometrically precise, microscopic, minute, monocratic, narrow, nice, obloquy, oppressive, overbearing, overconscientious, overruling, overscrupulous, particular, peremptory, perfectionistic, picky, pinpoint, pitiless, precise, precisianist, precisianistic, precisionistic, priggish, prudish, punctilious, punctual, purist, puristic, puritanic, puritanical, refined, reflection, religious, religiously exact, repressive, right, rigid, rigorist, rigorous, rugged, ruthless, scientific, scientifically exact, scrupulous, scrutinizing, selective, sensitive, severe, slam, slur, square, staunch, stern, stint, straitlaced, stricture, stringent, subtle, suppressive, tender-conscienced, thorough, tough, tyrannical, tyrannous, uncompromising, undeviating, undistorted, unerring, unsparing, unsympathetic, veracious, veridical/} sub warnings { return split /,\s+/, qq/admonishing, admonition, admonitory, advice, advising, advisory, advocacy, alerting, augural, blackmail, briefing, bulldozing, call, call for, caution, cautionary, cautioning, caveat, claim, clue, commination, consultation, consultative, consultatory, contribution, council, counsel, cue, demand, demand for, denunciation, determent, deterrence, deterrent, didactic, direction, directive, draft, drain, duty, empty threat, exaction, exemplary, exhortation, exhortative, exhortatory, expostulation, expostulative, expostulatory, extortion, extortionate demand, foreboding, forerunning, foreshadowing, foreshowing, foretokening, forewarning, frightening off, guidance, heavy demand, heavy with meaning, hint, hortation, hortative, hortatory, idea, idle threat, imminence, implied threat, imposition, impost, indent, indicative, insistent demand, instruction, instructive, intimidation, intuitive, levy, meaningful, menace, monition, monitorial, monitory, moralistic, nonnegotiable demand, notice, notificational, notifying, office, opinion, order, parley, passing word, pointer, preachy, precursive, precursory, predictive, prefigurative, preindicative, premonitory, presageful, presaging, prognostic, prognosticative, promise of harm, proposal, recommendation, recommendatory, remonstrance, remonstrant, remonstrative, remonstratory, requirement, requisition, rush, rush order, sententious, significant, steer, suggestion, sword of Damocles, talking out of, tax, taxing, thought, threat, threateningness, threatfulness, tip, tip-off, tribute, ultimatum, whisper/}
retroperl retro perl in Meditations
No replies — Read more | Post response
by Anonymous Monk
on Sep 02, 2019 at 15:41
(OT) Revisionist History Lesson in Meditations
6 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 20, 2019 at 07:25
What modules should be added to the corelist? in Meditations
10 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 16, 2019 at 09:17
Teen Perl in Meditations
1 direct reply — Read more / Contribute
by Anonymous Monk
on Aug 09, 2019 at 03:14
    Will Braswell talks about "the Perl 11 Master Plan to make Perl the king of languages again" in the "State of the Scallion Address" at The Perl Conference 2019 in Pittsburgh. Step 1 of the plan: "We're going to have to educate young people". Perl has this hidden gem of a tutorial which was originally a multi-page website titled "Tinkering With Perl: A Child's Guide" that survives as a single webpage (without the enchanting subtitle) at https://cjshayward.com/perl/

    Will Braswell - "The State of the Scallion Address"
    https://www.youtube.com/watch?v=NyphRo5roV0

    The Perl 11 Master Plan
    https://www.youtube.com/watch?v=NyphRo5roV0&t=27m20s

Perl growth in India, China, Russia, Germany and Romania in Meditations
No replies — Read more | Post response
by Anonymous Monk
on Jul 05, 2019 at 17:22
    A recent comment on r/perl claims that Perl is growing "nicely" in several key nations of Europe and Asia. The author cites their own experience and google as sources:

    "If my google alerts don't mislead me Perl is growing nicely in India, China, Russia and Germany... I can testify to growth in Romania, based on the pressure the HR people are putting on me to recruit people from the places I worked before."

    I share this good news hoping it will make you happy; and also seeking confirmation from those who know where to find such information.

    https://old.reddit.com/r/perl/comments/btt9e9/every_time_i_hear_perl_is_dead_i_think_of_the/eqdno37/

Why is Perl 4 so popular? in Meditations
1 direct reply — Read more / Contribute
by Anonymous Monk
on Nov 01, 2018 at 23:37
    Why are so many contenders to the throne of Perl nothing but a cheap copy of Perl 4?

    PHP, Python, Ruby, Javascript all start by copying Perl's worst practices, according to computer scientists, to become immensely popular, with no strict and globals everywhere.

    But the fun never lasts because they eventually succumb to aspersions of computer scientists to add all sorts of cruft to enforce austerities that satisfy obsessively compartmentalized minds.

    I think the reason is this: Languages like Perl force computers to think like people, rather than forcing people to think like computers.

    Don't get me wrong, we need the scientists to build and maintain the playgound so we can play, but we also need them to get the heck out of our way, and to stay away!

    Hard Fork Perl with a trendy cool name and make sure the batteries are included by throwing in a kitchen sink of about 1000 of the most awesome CPAN modules in a way that will do everything and run everywhere and you may have (another) winner.

    Perl 6, seriously, this is sad:

    
    $input.close or die $!;
    close($output);