Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Meditations

( #480=superdoc: print w/replies, xml ) Need Help??

If you've discovered something amazing about Perl that you just need to share with everyone, this is the right place.

This section is also used for non-question discussions about Perl, and for any discussions that are not specifically programming related. For example, if you want to share or discuss opinions on hacker culture, the job market, or Perl 6 development, this is the place. (Note, however, that discussions about the PerlMonks web site belong in PerlMonks Discussion.)

Meditations is sometimes used as a sounding-board — a place to post initial drafts of perl tutorials, code modules, book reviews, articles, quizzes, etc. — so that the author can benefit from the collective insight of the monks before publishing the finished item to its proper place (be it Tutorials, Cool Uses for Perl, Reviews, or whatever). If you do this, it is generally considered appropriate to prefix your node title with "RFC:" (for "request for comments").

User Meditations
automateaching -- part 2: proof of concept
1 direct reply — Read more / Contribute
by Discipulus
on Sep 30, 2020 at 04:45
    Only Perl can teach Perl
    Discipulus

    Introduction

    This is the follow up of Perl Automateaching -- part 1: brainstorming so read it first to have an idea of my intentions even if the pseudocode presented there is not what I currently plan.

    I have choosen the name for this project and it will be Perl::Teacher as it is clear and explicative.

    This post is a mere proof of concept about Perl teaching and, yes! it can be done! I'd like to be billionaire to hire super skilled perl geeks to develop my idea... but let's say they are all busy at the moment :) so the pupil (discipulus in Latin) will squeeze his brain and will dress teacher dresses. Contributors are welcome!

    In the final form Perl::Teacher will be document oriented, ie: it will analyze perl programs wrote by the pupil in physical files. But in the current proof of concepts various student's attempts are hardcoded into the below program contained in scalars from $work_01 to $work_n and with a $solution_code

    Also the final form of Perl::Teacher will be a bit interactive presenting and reviewing assignements and telling small lessons, but for the moment nothing of this is done.

    So running the below program you will see a serie of attempts to satisfy the assignemnt and results of tests applied to provided code fragments.

    Modify the $debug variable to 1 or 2 to see much more messages.

    Proof of concept

    Here my efforts up now (Ignore the warning you'll receive: Having more than one /x regexp modifier is deprecated at .../perl5.24-64b/perl/site/lib/Perl/Critic/Policy/ValuesAndExpressions/RequireInterpolationOfMetachars.pm line 110. beacuse it is a problem of Perl::Critic itself: see resolved issue on github)

    Implementation (current)

    As you can see there is a lot PPI stuff but not exclusively. Tests are execuded in order from 001 to 00n and if a test fails the current mini program is rejected.

    Each test can contain different steps, the first one being the optional run that simply sends the current code to a sub: this preliminary, optional test passes if the sub returns 1 and fails otherwise. Here it is used only to check if the program compiles ( see below for future ideas ).

    The second step of a test is select_child_of and it expects a PPI class name and a serie of subtests. Each PPI element of the specified PPI class, for example PPI::Statement::Variable (a variable declaration) will be processed to see if they contains PPI elemnts which satisfy all subtests. The first PPI element passing all subtests is returned by select_child_of and becomes a candidate for further inspections.

    Infact if evaluate_to is also specified, the current PPI element is, take a deep breath, keep calm, string evaluated to see if it holds the wanted value. And hic sunt leones or here are dragons because eval only returns the last statement value. Search the code above for the string dirty trick to see my workaround. For me it is a genial solution, but wait, I'm the guy who string eval'ed entire CPAN.. :) so improvements are warmly welcome.

    This form of testing is a proof of concepts: is not the final form of the testing framework needed by Perl::Teacher

    When a miniprogram passes all tests it is evaluated by Perl::Critic to give more hints to the student. Eventual policy violations will not make the program to be marked as wrong, but are just presented as suggestions.

    A note about flexibilty: looking carefully at the assignement you will notice that @letters and $result are constraints. Not the same for the intermediate scalars containing the first element and the last one.

    Implementation (future)

    module design

    The main Perl::Teacher module will provide only a framework to produce courses. The $teacher will load or create a configuration will have methods to deal with the student's input and to emit messages, but the main activity will be to load and follow courses plugins of the class Perl::Teacher::Course

    In my idea the course creator will publish Perl::Teacher::Course::EN::BasicVariables or Perl::Teacher::Course::IT::RegexIntroduzione all being child of the main Perl::Teacher::Course class. These courses have to be pluggable to the $teacher object ( Module::Pluggable probably but I have to investigate it further)

    Each course will contain a serie of lessons published a sub modules, as in Perl::Teacher::Course::EN::BasicVariables::01_strings , ..::02_lists etc.

    Yes I know: very long names.. but this will ensure a clarity of intent and of usage, in my opinion.

    ( update October 14 2020 see the related question Module design for loadable external modules containing data )

    lessons

    Each lesson will contain an ordered serie of optional elements: zero one or more assignement, multiple test elements possibly interleaved by one or more discourse and direct question.

    So a possible flow can be:

    Suggestions on module design are warmly welcome, but i want to keep it as simple as possible, not spawning objects for everything.

    tests

    Tests presented in the above code are too semplicistics to cover each teaching activity. I need beside positive tests also negative ones for example to prevent the use of modules, or all modules but one, to prevent external program execution and so on. Theese tests will be quite on success and will emit messages only on failure: "dont do this!".

    I can use Test::Script to add tests about correct overall syntax check, behaviour of STDOUT and STDERR given different arguments and so on.

    Then Perl::Teacher will provide its own tests like ones presented above: evaluate_to ( evaluate_at is probably a better name as it eval the code at a certain line), is dirty but it seems to me a viable option not so risky given the super small and controlled environment. I also plan a method named evaluate_subs which will grab al subs to test them.

    I have to mix all this features in a clean and easy to use interface. Suggetions are welcome.

    student interaction

    During a lesson the student must have the possibility to review the current assignement, to receive hints and be pointed to relevant documentation. Part of this is roughly done in the presented code using hints and docs embedded in tests. Can be and must be improved.

    I like to add a TIMTOWTDI discourse at the end of each lesson showing more ways to accomplish, even if not in the very same way, the assignement.

    Every output, comprensive of examined code, errors and hints, emitted during 03_array_manipulation must be saved into a 03_array_manipulation.history file so that the student can review the whole lesson including errors commited and pitfalls and the solution alongside different approaches to the same problem. Passing the time this becomes a good source of knoweledge.

    further ideas

    Testing standalone scripts is an idea haunting me since years. Modulino is an approach. I can be mad enough to take the original PDOM of a given program, then save all subs and use PPI method prune to delete them from the PDOM, then wrap the rest into a new main_original_program sub, add it to a new PDOM along with all previously saved subs. Then I could do the obtained file and test it nicely. A lot of cut 'n paste and probably error prone, but can be a path to explore.

    I'd like also my Perl::Teacher to be as much possible input/output agnostic: implement a way to interact with the console leaving open the possibility to be used by a web interface too: how to do this?

    I'd like to ear your opinions about this project, sugesstions on module design and implementation of its parts, comments to the above proof concepts and everything you want to share.

    L*

    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Perl folks come through yet again
1 direct reply — Read more / Contribute
by stevieb
on Sep 27, 2020 at 22:51

    I've had a long ride of negativity over the past few years, and I haven't coped very well.

    I want to thank all the Perlers (Monks and external). My life was saved.

    My tears can't begin to describe appreciation I have for the outpouring of care you've shown, once again.

Diary of a Zydeco experiment - E03 - Errors for fun and success
1 direct reply — Read more / Contribute
by Smonff
on Sep 22, 2020 at 15:29

    So today for the third episode of this diary, and after Diary of a Zydeco experiment - E02 - History, I would like to share a nice error message that I encountered while working on the modeling of my project. It can look strange to be happy about encountering an error message, but this one made my life really easier. It is still not about Zydeco directly but about one of the stable technology it relies on. Please don't look too deeply at the examples, they are mostly sarcastic but not very well structured on the OO side for now.

    So we have this role, that summarize very naively what a Buyer can do:

    # lib/Wildlife/Behavior/Buyer.zydeco.pm role Buyer { requires money; method acquire ( Num $price ) { say "I bought !"; } method sale ( Num $price ) { say "I sold !"; } }
    There is also an Exhibit role, that I will show only for the fun, but it is mostly distraction at this point:
    # lib/Place/Behavior/Exhibit.zydeco.pm role Exhibit { has exhibition ( type => ArrayRef ); has artist ( type => ArrayRef ); has artwork ( type => ArrayRef ) method display { say "Shoooow"; } }
    Then we have a Gallerist class, that consumes the Buyer role. You will maybe notice that there is a tiny mistake in this class (we'll come back a bit later on the mistake so don't look too much):
    # lib/Art.pm package Art { use Zydeco; class Place { has space; include Place::Behavior::Exhibit; include Wildlife::Behavior::Buyer; class Gallery with Exhibit, Buyer { has artwork ( type => ArrayRef ); has artist ( type => ArrayRef ); has event ( type => ArrayRef ); has owner; has public; } } }
    A test:
    # t/gallery.t use v5.16; use Test::More; use Art; my $gallery = Art->new_gallery( space => 1000, exhibitions => [ "Foo", "Bar" ], owner => "Arty Person", money => 10_000_000 ); ok $gallery->does('Art::Exhibit'), 'Gallery does role Exhibit'; ok $gallery->exhibitions, 'Gallery got an exhibitions attribute'; ok $gallery->owner, 'Gallery got an owner'; can_ok $gallery, 'acquire'; can_ok $gallery, 'sale';
    Let's run it! But it won't go very well.
    smonff@padi:~/projects/Art-World$ prove -lv t/15_gallery.t t/15_gallery.t .. Can't apply Art::Buyer to Art::Gallery - missing + money at /home/smonff/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl +/5.32.0/Moo/Role.pm line 307. BEGIN failed--compilation aborted at (eval 269) line 1. at /home/smonff/perl5/perlbrew/perls/perl-5.32.0/lib/site_perl/5. +32.0/B/Hooks/EndOfScope/XS.pm line 26. Compilation failed in require at t/15_gallery.t line 3. BEGIN failed--compilation aborted at t/15_gallery.t line 3. Dubious, test returned 2 (wstat 512, 0x200) No subtests run Test Summary Report ------------------- t/15_gallery.t (Wstat: 512 Tests: 0 Failed: 0) Non-zero exit status: 2 Parse errors: No plan found in TAP output Files=1, Tests=0, 2 wallclock secs ( 0.03 usr 0.00 sys + 2.00 c +usr 0.10 csys = 2.13 CPU) Result: FAIL
    What I want to focus on is the Can't apply Art::Buyer to Art::Gallery - missing money part.

    The error message is launched by a croak call in the _check_requires() method of Role::Tiny.

    croak "Can't apply ${name} to ${to} - missing ".join(', ', @requir +es_fail);

    Once we add the right attribut to the Gallery class, everything goes well:

    class Gallery with Exhibit, Buyer { has artwork ( type => ArrayRef ); has artist ( type => ArrayRef ); has event ( type => ArrayRef ); has owner; has public; has money; ... }
    And we run the tests again:
    smonff@padi:~/projects/Art-World$ prove -lv t/15_gallery.t t/15_gallery.t .. ok 1 - use Art; ok 2 - Gallery does role Exhibit ok 3 - Gallery got an exhibition attribute ok 4 - Gallery got an owner ok 5 - Art::Gallery->can('acquire') ok 6 - Art::Gallery->can('serve') ok 7 - Art::Gallery->can('sale') 1..7 ok All tests successful. Files=1, Tests=7, 2 wallclock secs ( 0.03 usr 0.00 sys + 2.30 cus +r 0.16 csys = 2.49 CPU) Result: PASS
    We actually don't even need to check the attributes in details.

    What I found amazing is how the error message makes sense. It just tells what should be done to fix the problem: adding a money attribute to the Gallery class. But more than that, it have a deeper meaning, that is exactly the point og this project. I mean you wouldn't have an art gallery with zero money would you? This is what I call efficient and reliable object oriented programming thanks Zydeco making a great use of the stable technologies it is built on (like Role::Tiny).

    So far, my overall use of Zydeco is very satisfactory during the application modeling phase. Some could say that I could draw some class diagrams and not coding, but the Zydeco use is so easy and non-verbose that it really make possible to focus ont the modeling and not on the coding: focusing on listing attributes, methods, roles and their relationship, not on the implementation.

    🌸
Diary of a Zydeco experiment - E02 - History
No replies — Read more | Post response
by Smonff
on Sep 15, 2020 at 04:03

    So here is the history of what lead me to Diary of a Zydeco experiment - E01 - Introduction. This is a long term continuation of an art project started circa 2006.

    In 2005, I got a metal box and colored carton cards and called this Le Fichier. It was basically a database of artworks ideas. I was trashing all ideas I could have of serious or weird potential artworks. It was inspired either by Roland Barthes, who was actually working with those kind of cards, Georges Perec, who was exploring potentialities, and Édouard Levé Oeuvres, a huge catalog of potential artworks (he later comited suicide after describing his own Suicide in a book).

    2006 I initiated a FileMaker database of artworks to put the old style carton cards in computer form. I had no idea what I was doing at this time, being an art school student, at this time, programming was not massively taught as a fine art (unfortunately).

    In 2008 I benefited of an artist residency in an agricultural college with a creation grant of 10 000€. I wanted to keep working on my Art World and Creative Processes schemas projects initiated during art school. It didn't go very well because the Plastic Arts State Inspector didn't like what I was doing with her money and strongly advised to change orientation. In my opinion, it was a perfect thing that the institution itself would exhibit it's own workings. In the end, there was an exhibition, but she didn't come to the opening.

    Anyway, I ended up interviewing many Agents of the college, and went especially well with some natural sciences teacher. He recommended a manual were I found some schemas that I made some detournement: I used the geology science as a metaphor of art world. I used geology terms and language to describe social interactions that were not described in the art sociology fieldsee illustration or see full presentation.

    The residency ended up with the redaction of a rather precise documentation (maybe my first specification).

    Then I almost got beaten by a fellow artist who was participating in a collective exhibition mostly for the money and not for the fun. I guess he felt a bit provoked by my situationist theory.

    In 2008, I finally decided to start a training to learn programming and design a proper database and system for managing a virtual Art World. I became a web developer, but I totally forgot the ulterior motive.

    Sometimes I thought about it:

    • 2013 Perl try - I bootstrapped a Perl module with 5 abstract empty classes and then let it sleep on Github
    • 2017 Raku try - I restarted my project while trying to learn Raku (it was still Perl6 at this time), but learning Raku was too much effort and I abandoned again

    Thirteen years after the initial idea I am still thinking about it. This project is following me in my dreams. I'll give it another try.

    You'll tell me: this have nothing to do with OOP and Zydeco 🤔. Ok, we'll see this on Diary of a Zydeco experiment - E03 - Errors for fun and success.

    🌸
Diary of a Zydeco experiment - E01 - Introduction
4 direct replies — Read more / Contribute
by Smonff
on Sep 10, 2020 at 07:58

    Here is the first post of a small journal I want to keep about an experiment I will do with Zydeco. I hope the Perl Monks Meditations section is appropriate for this, if not, please feel free to redirect me on a better place (especially this is almost my first post here). I started to learn using Zydeco this week after suddenly getting abnormally excited about it. I guess Toby Inkster's marketing seemed to be very effective on me.

    Where am I coming from? I was mainly trained on Java in 2009, so I am a object-native programmer. I mean, I cannot really imagine building something that wouldn't be made of objects, but also, Perl doesn't enforce object orientation, so you can still do without it. I don't know a lot about the how Perl's built-in OO works. I mostly used some modules:

    • Moose - it is the de-facto OO module, recommended in lots of books and tutorials. I went into it when some systems I designed started to grow. You can do a lots of things with it, but it's difficult to use for prototyping for example
    • Mojo::Base - It is usually not described as an independent OO system, but it provides attributes and accessors, readable source code, methods, roles (through Role::Tiny), method signatures. It is extremely simple to use even for prototyping, just use Mojo::Base. I got so used to it while working on Mojolicious projects that I usually import it even on non-web project!
    • unfortunately, I don't think I ever tried Moo seriously

    Next time I'll speak about the purpose of my experiment that is in fact an artistic project: trained as an artist, I accidentally became a professional web developer while trying to learn skills for my next conceptual art piece. But nothing went in the right way. Ten years afters, I am still working on it.

    Conttinue reading Diary of a Zydeco experiment - E02 - History.
    🌸
What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff
17 direct replies — Read more / Contribute
by likbez
on Sep 10, 2020 at 02:44
    Note to zealots who consistently put negative ratings on my comments:
    I do not care, but you prevent people who are not logged to the site from reading them and as such you censor my speech. Please remove them. This is a free forum not your clique watering place. The fact that you are unable to appreciate or understand them does not mean that they have no value to other people. Not all users here are Perl zealots. As Prince Talleyrand recommended to young diplomats: first and foremost not too much zeal. This is fully applicable to Perl advocacy. On other words by behaving like a clique you are harming Perl acceptance and future.
    What esteemed monks think about changes necessary/desirable in Perl 7 outside of OO staff. I compiled some my suggestions and will appreciate the feedback:
    1. [Edited] [Highly desirable] Make a semicolon optional at the end of the line, if there is a balance of brackets on the line and the statement looks syntactically correct (optional pragma "soft semicolon", similar to the solution used in famous IBM PL/1 debugging compiler). That can help sysadmins who use bash and Perl in parallel and work from command line with vi or similar editors, and are not using such editors as Komodo Edit which flag syntax errors. If might make sense to enable this pragma only via option -d of the interpreter. In this case it will suit as a pure debugging aid, cutting the number of iterations of editing the source before actual run. It does not make much sense to leave statements without semicolons in the final, production version of the program. See, for example, the discussion in Stack Overflow Do you recommend using semicolons after every statement in JavaScript
    2. [Highly Questionable] Introduce pragma that specify max allowed length of single and double quoted string (but not any other type of literals). That might simplify catching missing quote (which is not a big problem with any decent Perl aware editor anyway)
    3. [Highly desirable] Compensate for some deficiencies of using curvy brackets as the block delimiters:
      1. Treat "}:LABEL" as the bracket closing "LABEL:{" and all intermediate blocks (This idea was also first implemented in PL/1). [Edited]This feature also makes complex nesting structures more reliable, and can't be compensated with the editor, as people often just forget to check and assume that a complex nesting structure is OK, while in reality it is not. Some people argue that complex nesting structures should not exist. Those should not use this feature at all, but we should not allow them to dictate how we should program our scripts, especially in areas they have no clue about. For example, hand-written lexical and syntax analyzers and similar scripts with recursion and a very complex decision making.
      2. [Edited]Treat "}.." symbol as closing all opened brackets up to the subroutine/BEGIN block level and }... including this level (closing up to the nesting level zero. ). Along with conserving vertical space, this allows search for missing closing bracket to be more efficient. It might be possible to treat them as macros, which interpreter expands in the source code to regular brackets. Like soft-semicolons this feature mainly benefits those who use command like and vi, not some sophisticated GUI editor and allows dramatically cut the area of search for missing bracket in long scripts. .
    4. Make function slightly more flexible:
      1. Introduce pragma that allows to define synonyms to built-in functions, for example ss for for substr and ix for index
      2. Allow default read access for global variables with subroutines, but write mode only with own declaration via special pragma, for example use sunglasses;
      3. Introduce inline functions which will be expanded like macros at compile time:
        sub subindex inline{ $_[0]=substr($_[0],index($_[0],$_[1],$_2])) }
    5. As extracting of sub-string is a frequent operation in text processing scripts (for example to limit the scope of index function, or regular expression) in many cases it is more convenient to have indexes of starting and ending symbols, not a starting symbol and length. Also extracting of a sub-string sometimes is performed by eliminating head and tail with particular sets of characters like in tr/.../.../d ; often those characters are white space, a frequent operation for which something less general then regex might be beneficial.
      1. Adopt "range" notation. Allow to extract a sub-string via : or '..' notations like $line [$from:$to] (label can't be put inside square brackets in any case)
      2. Generalize chop and chomp with rtrim (see below).
      3. [Edited] Implement similar to head and tail functions called ltrim and rtrim as well as trim which can work with the set of characters like tr, not only integers. or substrings :

        trim(string,tt/leftcharacter_set/, tt/right_character_set/);
        [Edited]

        which deleted all characters from the first character set at the left and all characters from the second character set from the right, If only one set is given it uses for trimming both at the left and right

        Similarly ltrim($line,7) is equivalent to substr($line,7) but can be called as subroutine, not only as function. Similarly ltrim($line,'&lth1;) is equivalent to substr($line,max(0,index($line,'<h1')). In case of usage of tr datasets it should operate similar to trim but only on one "side" of the string --left or right.

    6. Allow to specify and use "hyperstrings" -- strings with characters occupying any power of 2 bytes (2,4,8, ...). Unicode is just a special case of hyperstring
      1. $hyper_example1= h4/aaaa/bbbb/cccc/;
      2. $hyper_example2= h2[aa][bb][cc];
      3. $pos=index($hyper_example1,h4/bbbb/cccc/)
    7. Put more attention of managing namespaces.
      1. Allow default read access for global variables, but write mode only with own declaration via special pragma, for example use sunglasses.
      2. Allow to specify set of characters, for which variable acquires my attribute automatically, as well as the default minimum length of non my variables via pragma my (for example, variables with the length of less then three character should always be my)
      3. Allow to specify set of character starting from which variable is considered to be own, for example [A-Z] via pragma own.
    8. Analyze structure of text processing functions in competing scripting languages and implement several enhancements for existing functions. For example:
      1. [Trivial to implement]Allow TO argument in index function, specifying upper range of the search. That can help to exclude unnecessary use of substr to limit the range of search in long strings
      2. [Trivial to implement]Extend the function tr with two new options: E -- exclude, which stops translation at the first symbol which it not in set1 and returns the position of this symbol, and R which can be used with option E to scan string in the reverse direction like rindex. For example, $line=~tr/ \t\n//dER will remove whitespace from the end of the string, while $line=~tr/ \t//dE will remove leading whitespace. Also those new options can be used for searching the position of a symbol in the string more efficiently, for example $pos=$line=~tr/_a-zA-Z//cE will return the position of the first letter in the string.
      3. Implement "delete element" function for arrays.
    9. Improve control statements
      1. [Edited] Eliminate keyword 'given' and treat for(scalar) as a switch statement. Disable smart matching by default. Interpreter should flag as an error if no $_ used in when construct to allow optimization (in this case elsif should be used:
        for($var){ when($_ eq 'b'){ ...;} # means if ($var eq 'b') { ... ; last} when($_ &gt;'c'){...;} } # for
      2. [Questionable] Extend last to accept labels and implement "post loop switch" (See Donald Knuth Structured Programming with go to Statements programming with goto statements)
        my rc==0; for(...){ if (condition1) { $rc=1; last;} elsif(...){$rc=2; last} } if ($rc==0){...} elif($rc==1){...} elif($rc==3){...}

        [Edited]One possible implementation would be usage of Pascal-style local labels (limited to the block in which they are defined), each of which corresponds when in the loop body

        for ...{ when (...); when (...); }after{ default: 1: ... 2: ... }
Getting better at this?
2 direct replies — Read more / Contribute
by Lady_Aleena
on Sep 06, 2020 at 20:29

    Hello everyone.

    I think I have made some improvements on how I write and use what I write.

    Since I began using git, I have made several changes to my code for my site.

    First, I moved everything used only for my site and have no intention of sharing on CPAN into one directory/name space called Page, This is the code so many dislike, so now it is all in one place away from everything else most are somewhat neutral about.

    After that bit of reorganization, I wanted to get the code not used for my site away from my site's code, so decided to do something about it. After a lot of digging on CPAN to get some site related code out, I had to know where to put external data used in half a dozen modules. It took me a while to figure it out. Once I did, File::ShareDir made it into my code.

    Next, I had to get my site's modules out of PERL5LIB, so I finally used FindBin after fighting against it all these years. I had been putting my site's lib into PERL5LIB since I was using Windows XP. It followed through when I switched to Debian. So, now $HOME/perl5/lib/perl5 is the only lib in PERL5LIB.

    Once I got that done, I had to figure out where to move the site independent modules to.

    I moved the ones I use for my personal non-site scripts to $HOME/bin/files/lib. These are the reason I learned how to use FindBin. I know it is not the best place for them, but they are not pretty and are not even version controlled now.

    I moved the ones I want to share to $HOME/mods/lib where I can write tests and whatever else I need to learn.

    There are some duplicate modules in my site's lib dir as are in mods/lib, but that will change once I get those packaged and on CPAN.

    I thought some of you might be interested in these little changes in my coding practices; some have been arguing with me over them for a very long time. I hope that the changes I made are slight improvements. If you are interested in looking at what I have done in the past two months, you can see my site's and module's repositories. I am trying to stay excited about sharing, but it can be hard when I see just how much more I need to do to get these ready for it.

    Have a nice day everyone...

    I hope this was not too scattered.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
When Perl saved the day (and Python couldn't)
3 direct replies — Read more / Contribute
by Anonymous Monk
on Aug 28, 2020 at 15:59

    Yes, I know this is not a place to rant, nor is this place to talk bad about other languages, but heck, I am going to rant anyways....

    So I started my scripting journey (short and irregular) with Perl. It enabled me to write scripts pretty fast with least knowledge of the language in particular and programming in general. Job requirements made me take a long break from Perl and Scripting. I started learning Python, not because I had to write scripts, but to "check mark" a training requirement. It's a good language, nothing against it. I was happy on the learning journey, until a requirement came up to automate some alerts and that is when my troubles started.

    The client for which I was to do the automation has strict internet access policies, so no access to the internet from the servers used for environment management. Also, no admin access. I had promised to automate some stuff (my bad, I should have first checked the requirements). Python would not install, not even within the directories for my account. I was at wit's end. I tried downloading again thinking may be the file got corrupted, but same result. My colleague managed to install it for his servers (different client) but kept getting errors while trying to send out emails. So we both were kind of upset and pissed off.

    And then I remembered, Strawberry Perl. Downloaded it, pushed the installer to the servers (Yes, I again had to raise a request for that as well, and no they would not allow any special permissions). To my amazement, it installed without any errors!!. And every conceivable module I wanted was there!!

    This was two days ago...just now finished writing the scripts, sent a test email to myself, then sent it to the required DL Email. Informed my manager and the concerned client folks and they were all happy!!

    Now for my colleague, he too installed the same, I helped him out with the scripts, and I dunnowhathappened, but the emails just worked with Perl. Yeah this sounds stupid, but it didnt work with Python, but , it worked with Perl!!

    Also I found that, for Perl, there are two kind of Email Modules, Ones that "create"/"format" Email and the others you use to "send" emails. Some modules may have both, and I could be wrong, but what I really liked is the modularity given here.

    May be I did something wrong while trying to install Python, may be not, I am not sure. May be I was stupid. But, end of the day, it was Perl that saved the day.

    So thank you Perl, Thank you Perl Developers and especially Strawberry Perl Team for saving the day.

    Rant Over.

My problems to understand the Perl documentation
7 direct replies — Read more / Contribute
by bojinlund
on Aug 22, 2020 at 16:40

    I have had some difficulties to read the Perl documentation. I have tried to understand why. This describes some of my problems to understand the documentation of the function split. I also make some proposals to what could be changed.

    Please note, I think I have understood most of what I need to understand, but it has taken a long time.

    Definitions of terms use in the description of the Perl language

    The definitions in perlglossary are rather general. Examples are:

    • function
    • Mathematically, a mapping of each of a set of input values to a particular output value. In computers, refers to a subroutine or operator that returns a value. It may or may not have input values (called arguments).
    • subroutine
    • A named or otherwise accessible piece of program that can be invoked from elsewhere in the program in order to accomplish some subgoal of the program. A subroutine is often parameterized to accomplish different but related things depending on its input arguments. If the subroutine returns a meaningful value, it is also called a function.
    • Operator
    • A gizmo that transforms some number of input values to some number of output values, often built into a language with a special syntax or symbol. A given operator may have specific expectations about what types of data you give as its arguments (operands) and what type of data you want back from it.
    • Operand
    • An expression that yields a value that an operator operates on. See also precedence.
    • Argument
    • A piece of data supplied to a program, subroutine, function, or method to tell it what it's supposed to do. Also called a "parameter".

    Terms I try to use in this post

    The Perl's perspective is missing in perlglossary. The definition of the Perl specific meaning of a term when used in the documentation of the Perl language is often missing.

    Meaning of terms used here are:

    • Function
    • What you want to be done.
    • Syntax pattern
    • The lines in the beginning of a description of a subroutine or operator. It shows the usages.
    • Subroutine
    • An implementation of a function described in perlsub. The input is called argument. Output is the return value.
    • Operator
    • An implementation of a function described in perlop. The input is called operand.

    Are the more implementation mechanisms of functions in Perl?

    I am aware of that a subroutine can be used as an operator and the reverse. In this post I have disregarded this.

    The description of Perl subroutine

    (In the index of "Language reference" the description is called "perlsub - subroutine function". What is a subroutine function?)

    I suppose the intention of perlsub is to describe the subroutine mechanism in Perl.

    This is one of the key parts to understand the usage of a Perl subroutine: From perlsub:

    The Perl model for function call and return values is simple: all functions are passed as parameters one single flat list of scalars, and all functions likewise return to their caller one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like. (Often a function without an explicit return statement is called a subroutine, but there's really no difference from Perl's perspective.)

    (According to the glossary a function refers to a "subroutine or operator that returns a value". The sentence in parenthesis is a bit confusing.)

    I have also been misled to think that the text above applies to all the functions described in index-functions.

    My proposal is to change the text to:

    The Perl model for subroutine call arguments and return values is simple: all subroutines are passed as arguments one single flat list of scalars. All subroutines return a return value, which is one single flat list of scalars. Any arrays or hashes in these call and return lists will collapse, losing their identities--but you may always use pass-by-reference instead to avoid this. Both call and return lists may contain as many or as few scalar elements as you'd like.

    And to add this:

    The arguments and return values are transferred using the argument stack. The arguments in the script source code is processed (evaluated) to store them in the argument stack. This is done before the subroutine definition is called.

    The syntax patterns in the beginning of the descriptions of functions implemented by subroutines, describe the content of the argument stack after the per-processing (evaluation) of the arguments.

    (argument stack must be added to perlglossary. Argument stack is described in perlguts

    The description of the function split

    In the description of the Perl functions it isn't always stated how a function is implemented.

    Split is not implemented as a subroutine and does not behave like a subroutine. At least the differences in the processing of the arguments compared to the normal processing of those to a normal Perl subroutine must be described.

    The syntax pattern for split describes the source code, not the result after per-processing of the arguments as it is for a subroutine.

    If you call split like this @rv = split $_[0], @_[ 1 .. 2 ] you get the return value undef. This is_deeply [ $_[0], @_[ 1 .. 2 ] ], [ qr{(:)}, 'a:b:c', 99 ] is ok.

    I had expected a warning or error exception.

    All of this is perhaps errors in the implementation if split.

    Summary

    I understand that it is impossible to do big changes to the documentation of Perl.

    Is there something small that can be done?

    I believe that one of the first thing to do is to improve is perlglossary. Definitions of meanings from a Perl's perspective should be added.

    Perhaps there could be two glossaries. One general and computer science focused and one with the Perl specific definitions used in the documentation of the Perl language.

Request for CO-MAINT on my CPAN distributions
No replies — Read more | Post response
by stevieb
on Aug 14, 2020 at 16:57

    Things are very up in the air for me, and I am uncertain whether I'll get back to my distributions or not.

    I am looking for a co-maintainer that I can assign to all of my published CPAN distributions in one fell swoop.

    This is not an attempt to find someone to own or actually maintain them directly, just someone who has ownership properties who would be reasonable and fair in possibly holding control in the event of a long-term/permanent absence of myself.

    I'd rather ask here first because vetting would be quick and easy. Otherwise, within the next two weeks, I'm throwing it open to the modules@ list as a free for all. I'd really, really prefer to have a controlled shared thing though.

    If anyone desires or has interest in fulfilling this request, full blown access to my Github repositories would be discussed shortly after co-maint permissions have been granted on the CPAN dists.

    Again, all of them for meta-maintenance mainly. If you want to work on them, that's good too. I will take requests for individual distribution takeover if I'm asked at steveb <> cpan org.

    My CPAN Distributions.

    Note:

    I also have ownership of a few other distributions in the shared memory arena, but they won't show up on my distribution list because I haven't formally uploaded an updated version of said software.

Marketing and branding for The Perl Foundation (TPF) poll
2 direct replies — Read more / Contribute
by Lady_Aleena
on Aug 07, 2020 at 21:51

    I came across the Marketing and branding for The Perl Foundation (TPF) poll, and thought you all might want to participate in helping the TPF come up with a marketing plan.

    My OS is Debian 10 (Buster); my perl versions are 5.28.1 local and 5.16.3 or 5.30.0 on web host depending on the shebang.

    No matter how hysterical I get, my problems are not time sensitive. So, relax, have a cookie, and a very nice day!
    Lady Aleena
Asking for help
3 direct replies — Read more / Contribute
by stevieb
on Aug 01, 2020 at 18:43

    Although I'm sure this post will be reaped, and I know why, but I'm asking anyways.

    I am very desperate for work. Things haven't been going well since we (wife and I) were evacuated and forced to move because of forest fire. Two months after I moved everything from my haven up north, I lost my job. Was able to acquire the odd contract here and there, but nothing stable. After the pandemic, nothing.

    I am at risk of literally losing everything, and my sanity is already half-way there.

    It's not like me to beg, but I am begging anyone, anywhere for work.

    My Perl experience speaks for itself. Most of you know I have a hefty background in global network engineering, as well as four years as a Solution Architect for an Identity and Access Management firm. I've also worked for what is now the largest online gaming corporation as their Global Network & Systems Engineer.

    If you've got a job, or even just a quick one-off contract that I could perform for you, please do let me know.

    If it matters, I've also got a few very good prototypes for the indoor grower (not specific to, but definitely geared towards cannabis growers) that no other company has done, but ran out of money to push it further. Funding towards this would help out as well, with the understanding that your due diligence will be honoured.

    I need something desperately.

    The Perl Jobs site hasn't had anything since late June, and all other jobs are being fought for at a scale I've never seen. I suspect that as my resume states a couple of 10 year gigs, folks grasp my age, and see that I'm not a young cookie out of college.

    Anything. I have no shame. I'm in a fight for our lives.

Split fake, an emulation of split
2 direct replies — Read more / Contribute
by bojinlund
on Jul 31, 2020 at 07:45

    Background

    I found an error in the documentation of split Function Split, bug or error in the documentation?.

    Had problems to understand the documentation of split. Decided to do an emulation of split to get a better understanding of split.

    Discovered that split does not behave like a normal subroutine Split does not behave like a subroutine.

    This is my try on an emulation of split. I hope this can help someone!

    Module Fake::Split

    The module implements split using the match operator m{}. It also includes utilities to debug the emulation.

    Used terms:
    Split divides a string in fields and separators. The /PATTERN/ matches the separators. The parts before, between and after a separator are the fields.
    sub splitF_match_pos

    sub splitF_match_pos returns a list with the position (pos) in the string for the start and end of matches. The list contains groups of pos with pos start and pos end of field, and a reference to an array. The array contains pos for start and end of separator and optional for each capture group, the start and end.

    sub splitF_case

    Identifies the patterns which needs special treatment in split.

    sub splitF_pos

    This routine handles split specific things. It uses the more generic splitF_match_pos.

    sub splitF_pos2txt

    The output is a textual presentation of the output from sub splitF_pos.

    sub splitF_pos2list

    Create a list of strings from the output of sub splitF_pos. The output is (should be) the same as that from split.

    sub splitF_test($;$$)

    Can be used to test the split emulation. See below!

    sub splitF($;$$)

    This is the emulation of split.

    If PATTERN, the first argument to split, is a match operator /STRING/ it must be replaced with qr/STRING/, a compiled regular expression.

    The syntax split /PATTERN/ and split are not supported

    My test of the module

    I have based my tests on the file t/op/split.t in the Perl source code distribution and on the examples in split.

    splitF_test_test.pl

    This script uses most of the /PATTERN/,EXPR,LIMIT combinations used in split.t. I had to change all /STRING/ to qr/STRING/. (I have not found any way to emulate split's way to delay the evaluation of its first argument).

    In the line is_deeply splitF_test(" ", "a b c"); returns splitF_test a suitable input to is_deeply.

    The output from splitF_test consists of two anonymous arrays, one with the output from the emulation and one from split, and a string with a dump of the argument /PATTERN/,EXPR,LIMIT

    My observations and questions

    The use of the Perl variable $#+

    It is important to use $#+ together with @- and @+. See my sub splitF_match_pos above.

    Inconsistency between m{} and split

    The need for this in sub splitF_pos2list

    if ( $field_start == $field_end && $sep_aref && $field_start == $sep_aref->[0] && $field_start == $sep_aref->[1] ) { info('SKIP intermediate field+separator, both are empty'); next; }
    indicates an undocumented inconsistency!?

    Arguments used together with Regexp Quote-Like Operators

    I have several times found limitations on what can be an argument to Regexp Quote Like Operators.

    One example is

    # while ( my $rv = $$str_ref =~ m{$pat_re}gc ) { does not work # but this works: my $str = $$str_ref; while ( my $rv = $str =~ m{$pat_re}gc ) {

    Are those limitations documented anywhere?

    A split function which behaves like a perl subroutine?

    The current split is a list operator with a lot of surprises and special cases.

    What about a parallel alternative, not so optimized implemented, which behaves like a normal subroutine. Perhaps a string study function with the arguments: pattern, reference to a string and returning a list with positions (not splitting the string in sub-strings). An optional parameter could be used to select special cases.

    A string study iterator is also useful.

dear Mom -
1 direct reply — Read more / Contribute
by perlfan
on Jul 26, 2020 at 22:25
    By far the most useful nodelet I've added to my PM layout is the CPAN nodelet. In today's installment of the cool module I TIL'd about is Mom - Moo objects minimally.

    I'm pretty outspoken about how ugly I think Moo, Moose, etc are and how we really just need to make these snausage factories more perlish. Util::H2O now has a friend on my list of steps in the right directionTM.

    I saw this interesting gem float by the nodelet, and the name alone was click bait enough for me to take a look. Congrats to the CPAN author for this brand spanking new module. It even uses parent.

    I'm not saying this is the way, but as I said before, it's thinking in the right direction.

Making $ Unicode-aware
3 direct replies — Read more / Contribute
by jo37
on Jul 26, 2020 at 14:31

    How bad is this idea:

    To my understanding, $ in a regex (without the m modifier) is equivalent to (?=\n?\z), i.e. "Match the end of the string (or before newline at the end of the string)". With Unicode, the meaning of "newline" may be extended to "Linebreak", aka \R.

    Wouldn't it be nice to make $ behave as (?=\R?\z) under some pragma or flag? (Without \z when the m flag is present, of course.)

    I believe this wouldn't even break much existing code. Invented for the "new" $ here.

    #!/usr/bin/perl use v5.14; use warnings; use utf8; use charnames qw(:full :short); use feature 'say'; for ("noeol", "nl\n", "cr\r", "cr_nl\r\n") { my $u_chomped = s/\R//r; say "$u_chomped:"; say 'matches $' if /^\p{word}*$/; say 'matches like $' if /^\p{word}*(?=\n?\z)/; say 'matches ' if /^\p{word}*(?=\R?\z)/; say 'matches \r$' if /^\p{word}*\r$/; say 'matches \r' if /^\p{word}*\r(?=\R?\z)/; say 'matches \r?$' if /^\p{word}*\r?$/; say 'matches \r?' if /^\p{word}*\r?(?=\R?\z)/; /^(.*)$/; say 'captured (.*)$' if $1 eq $u_chomped; /^(.*)(?=\R?\z)/; say 'captured (.*)' if $1 eq $u_chomped; /^(.*).$/; say 'captured (.*).$' if $1 eq $u_chomped; /^(.*).(?=\R?\z)/; say 'captured (.*).' if $1 eq $u_chomped; say "\n"; } __DATA__ noeol: matches $ matches like $ matches matches \r?$ matches \r? captured (.*)$ captured (.*) nl: matches $ matches like $ matches matches \r?$ matches \r? captured (.*)$ captured (.*) cr: matches matches \r$ matches \r matches \r?$ matches \r? captured (.*).$ captured (.*). cr_nl: matches matches \r$ matches \r matches \r?$ matches \r? captured (.*).$ captured (.*).

    Greetings,
    -jo

    $gryYup$d0ylprbpriprrYpkJl2xyl~rzg??P~5lp2hyl0p$

Add your Meditation
Title:
Meditation:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":


  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (7)
    As of 2020-12-03 20:46 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      How often do you use taint mode?





      Results (57 votes). Check out past polls.

      Notices?