http://www.perlmonks.org?node_id=1135479
Posts by Anonymous Monk
Perl joke heard on television in Meditations
3 direct replies — Read more / Contribute
by Anonymous Monk
on Mar 28, 2020 at 07:41
    Stacy Herbert: You know the flu is way more complicated than this corona virus. I think it's like four strands of RNA. It's so simple apparently the code for it fits on one single page, and this simple little tiny virus is taking down our hyper-complex globalized just-in-time system.

    Max Keiser: Yeah I think the COVID-19 is written in Perl, and the flu is written in C++.

    Keiser Report E1520 Gold: Problems with Exchange for Physical
    https://www.youtube.com/watch?v=wPGmut6_TEk&t=9m23s
    
Let's finish Imager::GIF in Meditations
1 direct reply — Read more / Contribute
by Anonymous Monk
on Feb 06, 2020 at 16:42
    Imager::GIF - a handy module for animated GIF processing - is a nice thought, with one semi-working method and problematic documentation (Re^2: Imager::GIF seems broken), that needs some help, as the docs say:

      TODO

      Implement the rest of the transformations (cropping, rotating etc).

    I needed to non-proportionally scale animated GIFs and implemented type=>nonprop in the scale method. Other desirable features include crop, watermark, and sharpening. Please share your mods and methods here.

    TODO:

  • https://metacpan.org/pod/distribution/Imager/lib/Imager/Transformations.pod
  • https://metacpan.org/pod/distribution/Imager/lib/Imager/Filters.pod

    Your local file:

    perl -MImager::GIF -le 'for (keys %INC) { print $INC{$_} if /GIF\.pm/ +}'
    My scale method:
    sub scale { my ($self, %args) = @_; my $ratio = $args{scalefactor} // 1; my $qtype = $args{qtype} // 'mixing'; # add qtype support $self->_mangle(sub { my $img = shift; my $ret = $img->scale(%args, qtype => $qtype); my $h = $img->tags(name => 'gif_screen_height'); my $w = $img->tags(name => 'gif_screen_width'); # add non-proportional scaling if ( $args{xpixels} and $args{ypixels} and $args{type} and $args{type} eq 'nonprop') { my $xratio = defined $args{xpixels} ? $args{xpixels} / $w : $ratio; my $yratio = defined $args{ypixels} ? $args{ypixels} / $w : $ratio; $ret->settag(name => 'gif_left', value => int($xratio * $img->tags(name => 'gif +_left'))); $ret->settag(name => 'gif_top', value => int($yratio * $img->tags(name => 'gif +_top'))); $ret->settag(name => 'gif_screen_width', value => int($xr +atio * $w)); $ret->settag(name => 'gif_screen_height', value => int($yr +atio * $h)); } else { # proportional scaling, from the original unless ($ratio) { if (defined $args{xpixels}) { $ratio = $args{xpixels} / $w; } if (defined $args{ypixels}) { $ratio = $args{ypixels} / $h; } } $ret->settag(name => 'gif_left', value => int($ratio * $img->tags(name => 'gif +_left'))); $ret->settag(name => 'gif_top', value => int($ratio * $img->tags(name => 'gif +_top'))); $ret->settag(name => 'gif_screen_width', value => int($ra +tio * $w)); $ret->settag(name => 'gif_screen_height', value => int($ra +tio * $h)); } return $ret; }); }
    Thank you!
Hacker News! Just another reinvented wheel: uni in Meditations
2 direct replies — Read more / Contribute
by Anonymous Monk
on Dec 13, 2019 at 23:49
    Four years and seven weeks ago our friend Ricardo SIGNES brought forth on this network, a new program, conceived by Audrey Tang: App::Uni! For some reason a year old clone of uni, written in Go, was advertised as "Hacker News" yesterday:
    Uni: Query the Unicode database from the CLI...
    https://news.ycombinator.com/item?id=21777025
    
    Usage of App::Uni:

    Identify a character:

    uni 
     - U+020AC - EURO SIGN
    
    Or a string:
    uni -c h
    h - U+00068 - LATIN SMALL LETTER H
     - U+020AC - EURO SIGN
     - U+000FD - LATIN SMALL LETTER Y WITH ACUTE
    
    Search description:
    uni /euro/
    ₠ - U+020A0 - EURO-CURRENCY SIGN
     - U+020AC - EURO SIGN
    𐡷 - U+10877 - PALMYRENE LEFT-POINTING FLEURON
    𐡸 - U+10878 - PALMYRENE RIGHT-POINTING FLEURON
    𐫱 - U+10AF1 - MANICHAEAN PUNCTUATION FLEURON
    🌍 - U+1F30D - EARTH GLOBE EUROPE-AFRICA
    🏤 - U+1F3E4 - EUROPEAN POST OFFICE
    🏰 - U+1F3F0 - EUROPEAN CASTLE
    💶 - U+1F4B6 - BANKNOTE WITH EURO SIGN
    
    Multiple words are matched individually:
    uni globe earth
    🌍 - U+1F30D - EARTH GLOBE EUROPE-AFRICA
    🌎 - U+1F30E - EARTH GLOBE AMERICAS
    🌏 - U+1F30F - EARTH GLOBE ASIA-AUSTRALIA
    
    Print specific codepoints or groups of codepoints:
    uni -u 2042
    ⁂ - U+02042 - ASTERISM
    
    uni -u 2042 2043 2044
    ⁂ - U+02042 - ASTERISM
    ⁃ - U+02043 - HYPHEN BULLET
    ⁄ - U+02044 - FRACTION SLASH
    
    AFAIK App::Uni does not have the -race (I mean -tone) or -gender switches of the Go uni so there was some innovation I guess.

    Anyway my meditation consists of encouraging Perl programmers to announce their wares on Hacker News, and other such websites.

    https://news.ycombinator.com/news
    
Perl Feels Good in Meditations
4 direct replies — Read more / Contribute
by Anonymous Monk
on Nov 17, 2019 at 13:02
    I wrote another really cool Perl program today! It's 200 lines of pure awesomeness. 140 lines are code with 7 subroutines using a couple of spiffy core modules. It has 40 lines of embedded documentation and a 20 line __DATA__base! It was working so good when I imagined how to make it into a module and *presto* an hour later it was a 250 line module with those smooth method chains.

    I do this so often my ~/bin has over 1000 programs and modules. One of these days I would like to upload them somewhere if it's not too complicated. Until then I am a one man CPAN ;-)

    My projects include command line programs, web apps, search engines, linguistic analysis, os enhancement, graphics, data visualization, and making Perl easier to use by exposing its buried treasures.

    What are you doing with Perl?


    "I think that TPF (The Perl Foundation) would be wise to expand its scope to Perl software projects in a similar manner to ASF (Apache Software Foundation)."--PerlDean
    https://old.reddit.com/r/perl/comments/dq1lzy/the_perl_masterplan/f65h3t6/
Request for Feedback: Perl Documentation Site in Perl News
5 direct replies — Read more / Contribute
by Anonymous Monk
on Oct 27, 2019 at 19:55

    The official Perl documentation site at https://perldoc.perl.org was recently overhauled. Independently, I put together a reimagined documentation site that would be hosted at https://perldoc.pl. In the interest of providing a documentation site that best serves the needs of the Perl community, we need your feedback. Please give both sites a try, in-depth if you want, or just how you would most commonly use the site. What do you like about the design or the functionality of each site? What is missing or can be improved? Any feedback regarding what you want from the Perl documentation site is helpful and appreciated. Please leave comments here or in the linked posts by Monday Nov 18th.

    blogs.perl.org comments

    Reddit comments

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
retroperl retro perl in Meditations
No replies — Read more | Post response
by Anonymous Monk
on Sep 02, 2019 at 15:41
    
    Perl 1-4 historical archive
    http://www.etla.org/retroperl
    
    Perl1 for recent Linux and *BSD
    https://github.com/kAworu/perl1/blob/minimal-changes/README.md
    
    Perl1 for Modern Linux, et al.
    https://github.com/TPF-Community-Advocacy/perl1.0/blob/master/README.md
    
    Perl2 for Cygwin on Windows 10
    https://github.com/bobbyjim/perl2/blob/master/README.md
    
    Perl3 for Raspbian 2019
    https://github.com/bobbyjim/perl3/blob/master/README.md
    
    Perl4::CoreLibs - libraries historically supplied with Perl 4
    https://metacpan.org/pod/Perl4::CoreLibs