Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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
How to Bisect Perl
No replies — Read more | Post response
by haukex
on Dec 27, 2019 at 14:42

    In several of my nodes, I've used bisection to figure out when certain bugs/features were fixed/introduced. I find this useful because it'll often uncover the discussion that went into a feature or the detailed reasons behind a bug. I thought I'd write about this process, since I don't always document how I ran each bisect.

    First, what is bisection? Basically, it's a (partly automated) binary search to find the exact commit where some behavior changed.

    A simplified example: Say you want to find out which Perl release s///r was introduced. So, you run perl -e 's///r' on the oldest Perl you've got, say 5.6, and on the newest, 5.30 - the former dies, the latter runs, confirming the change happened somewhere between those releases. So then you divide the search space into two, and run the same test on 5.18 - it works, so you now know the change must have happened between 5.6 and 5.18, and you don't need to test the other half of the search space. Divide the search space again, and run the test on 5.12 - it fails, so you know the change must have happened between 5.12 and 5.18. Repeat the process again, and eventually you'll find out that Perl 5.12 dies, but 5.14 works - so you've now confirmed that s///r was introduced in release 5.14, and you didn't have to test all 13 Perl releases from 5.6 to 5.30! (Technically, the change happened in a development version between those two releases, but for this example we've only looked at non-development releases as a stand-in for commits.)

    A real bisect is different from this example in that it works on the granularity of git commits, and it's mostly automated - the Perl source code includes scripts to assist you in running a git-bisect. And instead of using pre-built Perls, the bisection process will check out each commit of Perl and build it from scratch (even applying patches as needed to get older versions of Perl to compile). It can take half an hour to several hours to run a bisect, but once you set it running, you can go and do something else in the meantime.

Printing large numbers with commas to show thousands groups.
3 direct replies — Read more / Contribute
by jnorden
on Dec 26, 2019 at 20:13
    Here is yet another answer to this ancient and oft-asked question (for linux at least).

    The standard advice is found in perlfaq5, on perlmonks, and elsewhere. Using Number::Format or a commify() sub works well, but isn't very convenient for modifying existing code that was written with printf. It seems unlikely that perl's printf will ever support %'d and friends (see printf(3), scroll to "Flag Characters").

    However, almost any linux system has a /usr/bin/printf command with %' support. So, the simple definition

    sub cprintf {system('/usr/bin/printf', @_)}
    will let you use
    cprintf("There are at least %'d ways to do it!\n", 42e6)
    to print: There are at least 42,000,000 ways to do it!

    For this to work, your LC_NUMERIC environment variable should be set to a locale that has a "thousands separator", such as en_US.UTF-8. It seems to work quite well, at least for simple cases. To modify existing code, just change your printf's to cprintf's and add apostrophe's to the formats as needed. Less work than wrapping each argument with a subroutine call and changing each format to %s. It also helps keep things clear and readable.

    It's tempting to override the builtin printf, but that's not easy to do. The CORE documentation lists printf as a special keyword. (Playing with tied file-handles or other tricks might work, but doesn't seem worth it too me.)

    On the other hand, if you want to auto-magically commify *all* your %d's, you could use:

    sub cprintf { my($fmt)= shift; $fmt=~s/%(-?\d*)d/%'$1d/g; system('/usr/bin/printf', $fmt, @_) }
    And then  cprintf("%d", 42e6) will print 42,000,000.


    Happy Holidays, and best wishes for the new year!
    -Jeff

Defining, Testing and Documenting Perl?
2 direct replies — Read more / Contribute
by LanX
on Dec 23, 2019 at 12:03
    Hi

    I started to write a test script for "Boolean Operators" with and w/o "Short-Circuit" in Perl.

    And quickly found me needing to define and test "Truthiness" in Perl.

    (Wait ... "0 but true" is false? Remembered it differently ;-)

    And now I find myself obliged to also define "Contexts", because an empty list is also false.

    And "Data Types", because internally it's more difficult, than just Scalar, Array and Hash.

    It's a lot of work, but in the end it could help in many corners when done correctly:

    • Regression testing between Perl versions
    • Leading to a proper language definition
    • Bottom up documenting the language in POD
    • Helping to test cross implementations in other languages like in JS
    Properly done means that it needs to be axiomatic, i.e. higher level tests need to only use features proven in lower levels.

    Like so often, after a first success I find myself a bit stuck in the big picture.

    I'll throw in my first approach as is for meditation.

    There is a lot to be criticized, but my normal perfectionism is too risky and might lead to a never release cycle.

    Thoughts?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Perl hosting is hard to find
10 direct replies — Read more / Contribute
by harangzsolt33
on Dec 20, 2019 at 10:09
    I was searching for the cheapest Perl hosting online that also allows me to have 10 websites pointing to it. But I am finding out that cheapest is not necessarily good. Maybe I am wrong. But this is the third time I do business with a hosting company that promises to offer perl support and doesn't live up to its claims.

    I'm talking about Netfirms, 50webs, and 1dollar-webhosting.com. These are the three I have tried and paid for. They promised I would get perl scripting, and it wasn't included. I was told to buy the next level up. But if I have to upgrade, then why did they include perl in their special offer or advertising!? Anyway, I didn't get what I paid for, and I was disappointed. Is it common to see hosting companies that say they offer perl and then not deliver on their promise? I mean that's the only reason I chose these hosts, because they included perl in the list.

Dataflow programming on CPU and GPU using AI::MXNet
1 direct reply — Read more / Contribute
by bliako
on Dec 18, 2019 at 07:04

    Computational pipelines, often called Dataflows, are just Graphs describing the interaction of Data with Operators and other Data to produce more Data.

    a*b + c*d is a Dataflow.

    And so is a (feed forward) Neural Network: read input, distribute input matrix to first layer, pass it through activations, sum outputs and distribute to second layer and so on until the output layer. Deep Neural Networks are so complex, deep and convoluted that they thought dataflow programming (which is not new as a field) will aid their training and use. And so TensorFlow and MXNet and others were created.

    The really unfortunate thing is that most of these frameworks are investing heavily on Python interfaces even if internally they use C/C++ for obvious reasons :) . The fact that Python is a TIOOWTDI regime will lead this field to serious cargo-culting (e.g. "In a sparse network, it’s more likely that neurons are actually processing meaningful aspects of the problem." which I have seen before when working with Neural Networks, mid-90's), script-kidding practices and eventual stagnation. Of course the field will recover. And faster and sooner, if and when Python is replaced or other high-level-er (script) languages are equally supported. Nothing stops the machine taking over ...

    In Perl, there is an excellent set of modules written by Sergey Kolychev under AI::MXNet based on Apache's MXNet. Note that it is active and very recently updated: Feb 23, 2019 !!! That's a good sign.

    My cpu and I have spent a lot of cycles trying to install the pre-requisite libraries of Apache's MXNet written in C/C++ and offering also CUDA capabilities. Two hints: do not use github repo version and use Makefile (instead of that cmake).

    Now that I have it all installed (MXNet libraries, Perl module and also R package - unrelated to this post) I would like to share with you all just what size of doors this package opens by introducing a basic dataflow operating on scalars and matrices both on CPU and GPU! The very fact that this package offers, on the side, GPU capabilities within Perl makes it, in my opinion, very very promising. I can't see much offering GPU at CPAN at the moment and here we have one package which opens both GPU and Deep Learning worlds to Perl hackers. (I have no affiliation with S.Kolychev whatsoever)

    So, here is some code to get you started on implementing a pipeline to calculate e=a*b+c*d. At first these AI::MXNet::Symbol (e.g. a,b,c,d,e) will be scalars represented as 1-dimensional AI::MXNet::NDArray (which is somewhat similar to PDL's arrays):

    use strict; use warnings; use AI::MXNet qw(mx); # specify which context we want this dataflow to be executed in # for CPU use mx->cpu(0); (note, (0) does not mean cpuid or something, + it is not used) # for GPU use mx->gpu(0); (0 denotes gpu device id) my $ctx = mx->cpu(0); # create 1D arrays with values: 1, 2, 3, 4 for a b c d respectively # these are DATA my $a_data = mx->nd->array([1], ctx => $ctx); my $b_data = mx->nd->array([2], ctx => $ctx); my $c_data = mx->nd->array([3], ctx => $ctx); my $d_data = mx->nd->array([4], ctx => $ctx); # these are SYMBOLS my $a = mx->symbol->Variable('A'); my $b = mx->symbol->Variable('B'); my $c = mx->symbol->Variable('C'); my $d = mx->symbol->Variable('D'); # these is the EXPRESSION to evaluate # basically our dataflow graph (but still no data on it, just descript +ion) my $e = ($a*$b) + ($c*$d); print "e=".$e."\n"; # this is how we associate data with symbols and specify # whether we want to run this on CPU or GPU my $exe = $e->bind( ctx => $ctx, # this is how we bind data to symbols so our dataflow graph ca +n be "executed" # and a result comes out # Note: create the arrays on the same device as executing them +, i.e. context, ctx, # must be the same here and above in creating the arrays. args => {'A'=>$a_data, 'B'=>$b_data, 'C'=>$c_data, 'D'=>$d_data} ); # propage inputs to the output(s) $exe->forward(1); # we need the first (and only one at this case) output as PDL array print "output: ".$exe->outputs->[0]->aspdl."\n";

    And this is the result:

    output: [14]

    Now, let's replace 1-dimensional data with 2x2 arrays! Just create your data as thus:

    # 2d array data, initialised to these rows (edit: updated to specify c +tx too) my $a_data = mx->nd->array([[1,2],[3,4]], ctx => $ctx); my $b_data = mx->nd->array([[5,6],[7,8]], ctx => $ctx); my $c_data = mx->nd->array([[9,10],[11,12]], ctx => $ctx); my $d_data = mx->nd->array([[13,14],[15,16]], ctx => $ctx);

    But, wait because the * operator on matrices denotes element-to-element multiplication and not the actual matrix multiplication. For that we use:

    my $e = $a->dot($b) + $c->dot($d);

    And the result is:

    [ [286 308] [366 396] ]

    If not evaluating ginormous matrix expressions using a Dataflow framework (which will also parallelise when parallelisation is possible) was not enough we have here another huge door opening for you number crunchers and Perl hackers: the ability to do this using the GPU via CUDA! Just replace the context above with the GPU-related code. And there is light! In this way, CUDA can be used via Perl not only for doing neural network stuff but for any kind of computation which you can express in a Dataflow. For example, load two images as AI::MXNet::NDArray and multiply them on the GPU! Or do some signal processing by loading an mp3 voice file as NDArray! (this paragraph was a 5' later addition)

    One thing that does not add up is that AI::MXNet::NDArray says: "However, NDArray is row-major, unlike the PDL that is column-major.". But PDL is row-major too! So have that in mind.

    Sources+more reading:

    If that does not keep you excited over the Festivus, I don't know what will ...

    Thank you Sergey Kolychev ++

    bw, bliako

    ps. some last 5 min additions and cosmetic changes. Also note the comments in the code provided for more information.

Hacker News! Just another reinvented wheel: uni
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
    
Beware of global! And bless the local!
3 direct replies — Read more / Contribute
by alexander_lunev
on Dec 12, 2019 at 03:40

    Hello monks.

    Today I found that a little negligence can cause a week-long debugging.

    I wrote a program that uses Crypt::OpenPGP module, and for a strange reason module works great when I simply initialize it with keyrings from file, but it crashes when i first read keyrings from files and combines them for my needs and then initialize module with constructed keyring objects. Terrible crashes of the Perl interpreter itself (sic!) was accompanied by cryptic messages like these:

    Win32::API::parse_prototype: WARNING unknown parameter type 'PVOID' at + C:/Strawberry32/perl/vendor/lib/Win32/API.pm line 568. Win32::API::parse_prototype: WARNING unknown parameter type 'ULONG' at + C:/Strawberry32/perl/vendor/lib/Win32/API.pm line 568. Win32::API::parse_prototype: WARNING unknown output parameter type 'IN +T' at C:/Strawberry32/perl/vendor/lib/Win32/API.pm line 600. Argument "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0..." + isn't numeric in subroutine entry at C:/Strawberry32/perl/vendor/lib +/Crypt/Random/Seed.pm line 247.

    I was wondering - what have i done to bring this punishment upon me? I compared objects that come out from keyring-file initialization and from keyring-objects initializations with Data::Dumper and couldn't find a difference. I even saved constructed keyring objects to files and initialize Crypt::OpenPGP with this newly created files - still all was crashing. The holy fear seized me and I decided to start my journey to the depth of module forest to find deliverance. I walk through Crypt::OpenPGP to Bytes::Random::Secure, to know that road leads - as it was told to me in the cryptic omen - to Crypt::Random::Seed, line 247, which was a Call to Win32::API function:

    my $rtlgenrand = Win32::API->new( 'advapi32', <<'_RTLGENRANDOM_PROTO_' +); INT SystemFunction036( PVOID RandomBuffer, ULONG RandomBufferLength ) _RTLGENRANDOM_PROTO_ return unless defined $rtlgenrand; return ('RtlGenRand', sub { my $nbytes = shift; my $buffer = chr(0) x $nbytes; my $result = $rtlgenrand->Call($buffer, $nbytes); # <= 247

    My journey comes to a dead end, for I didn't find deliverance there. And I started from the beginning of my code, turning lines of code off one by one. And I found it.

    This is the code that was a root of all misfortunes.

    open my $fh, "<", $file or die "can't open $file"; $/ = undef; my $key_string = <$fh>; close $fh;

    If you're enlightened enough, you will see my sin right away. I'm not enlightened enough to see it right away, but a doubt crawls into my mind - could it be the line $/ = undef;? I stared at this line for a minute and go search wisdom on the Internet. And then I found the Truth. And as always the Truth was under my nose all the time, but I couldn't see it. It should be local $/ = undef;!

    I don't know if it is clean and right way to read all file in a string, but even the great Gabor Szabo blesses slurp mode by setting $/ = undef;. But beware if you read his great article not thoroughly! The great misfortune awaits those who forget about local in a rush! Like me for example.

    You see? Setting $/ = undef; globally make things broken all the way up to the Perl interpreter itself, which was casting strange messages on his way to crash.

    But why would anyone write about it again, and again, and again? Because, as it said in every language:

    Repetitio mater studiorum est.

    Repetition is the mother of all learning.

    Wiederholen ist die Mutter des Studierens.

    La répétition est la mčre de la science.

    Повторение - мать учения.

    Let my mistake will be a lesson to others. Using global variables is always a risky and erroneous path, local variables is the only way to enlightenment. But this is the Truth that we were told from the beginning and we are still making this silly mistakes. And while we code simple programs, errors are simple and debuggable. But when we become more mature - so are the errors that we cause by violation of a simple rules that we doesn't learned well from the start. Beware of global! And bless the local! Amen.

RFC: "assignary" operator ?= :
7 direct replies — Read more / Contribute
by richard.sharpe
on Dec 07, 2019 at 11:01

    Hello guys,

    I would like having new type of assignment operator in perl, the combination of assignment and ternary operator (therefore calling it "assignary"):

    ?= :

    Not in context of regular expressions, not related with (?=) in any way, but in regular assignment. I haven't found something like that in perlop.

    Suggested meaning:

    $var ?= "something" : "something else";

    would be equivalent to:

    $var = $var ? "something" : "something else";

    Advantage of the first: more compact, as not writing $var two times.

    What do you think about possible existence of such hybrid of ternary and assignment operators?

Jumbo Signatures extensions discussion
2 direct replies — Read more / Contribute
by Corion
on Nov 29, 2019 at 02:14

    dave_the_m has posted a long and very comprehensive thread to perl5-porters in which he outlines his plans for subroutine signatures. The plan is to get a consensus on the syntax of the various features and then to implement them over the next year. The goal is to have subroutine signatures out of experimental status by Perl 5.36. Whatever breaking of backwards compatibility with the existing (experimental) subroutines is necessary should go into 5.32.

    I have mostly copied the Synopsis section of each mail here, and I really encourage you to look at the mails themselves which contain far more discussion of the proposed behaviours.

    The separate threads are:

    Jumbo Signatures extensions discussion - the top level thread

    Here is a contrived example of a signature which demonstrates many of the proposals. Some of it will make more sense after each proposal has been read.

    sub foo ( $self, # parameter declarations starting with '?' examine, # but don't consume any further arguments: ?*@args, # @args is set to the equivalent of @_ with one # arg shifted; i.e. like a slurpy but peeking ahead # and not actually consuming any args; the '*' means # that each @args element is aliased to a passed arg ?$peek_a, # $peek_a is bound to next arg but without consuming + it ??$has_a, # $has_a is set to true if there's an argument for $ +a $a, # normal scalar parameter ?{ print $a },# embedded code block - runs code; doesn't shift arg +s Dog $spot, # works the same as 'my Dog $spot' $b :shared, # you can use normal variable attributes $c :ro, # at compile time, $c in lvalue context croaks \@ary, # aliases @ary to a passed array reference \%hash, # aliases %hash to a passed hash reference *$scalar, # aliases $scalar to the next argument # Constraints and coercions: $d!, # croak if $d not defined $e isa Foo::Bar, # croak if $e isn't of that class $f is Int where $_ > 0, # croak if $f not a positive integer $x = 0, # a default value $y?, # short for $y = undef \@array?, # short for \@array = [] :$name1 = 0, :$name2 = 0, # consume name-value pairs (name1 => ..., name2 => . +...) @rest # slurp up any remaining arguments ) { .... }

    Parameter Attributes

    sub f ($x :foo, $y :bar(baz) bar2(baz2), ...) { ... }

    analogous to:

    my $x :foo; my $y :bar(baz) bar2(baz2);

    Perl should support parameter attributes.

    What exactly should the semantics be? Lets first review the current syntax as applied to 'my' declarations:

    my ($x, $y) :foo(foo_arg) :bar(bar_arg);

    is roughly equivalent to

    use attributes (); my ($x,$y); attributes->import(, __PACKAGE__, \$x, "foo(foo_arg)", "bar(bar_ar +g)"); attributes->import(, __PACKAGE__, \$y, "foo(foo_arg)", "bar(bar_ar +g)");

    Named Parameters

    sub foo ( $pos1, # positional parameter; consumes 1 arg $pos2, # positional parameter; consumes 1 arg :$name1, # named parameter, consumes ("name1", value) arg +pair :$name2, # named parameter, consumes ("name2", value) arg +pair @rest, # consumes all unrecognised name/value pairs ) { ... }

    This seems a popular feature request: give Perl 5 something similar to Perl 6's named parameters.

    Querying Parameters

    ?$x peek ahead to the next arg ??$x peek ahead and see if there is a next arg ?@a peek ahead and copy all remaining args ?%h peek ahead and copy all remaining key/val arg pairs ?{ code } execute some code without consuming any args

    Sometimes you want to find out some extra information about the arguments and the state of argument processing. With @_ available, this can be done, if messily; if @_ isn't populated (see the "@_ Suppression" thread), then it becomes harder/impossible, unless some other mechanisms are added.

    @_ suppression

    @_ will not be set, unset or localised on entry to or exit from a signatured sub; it will still be the @_ of the caller. But any use of @_ within the lexical scope of sub a sub will warn.

    Aliasing and Read-only variables

    sub foo { # the lexical vars $a, @b and %c are aliased to the things poi +nted # to by the reference values passed as the first three argumen +ts: \$a \@b, \%c, # $d is aliased to the fourth arg: *$d, # $e is aliased to the fifth arg, but at compile time, any us +e # of $e in lvalue context within this lexical scope is a compi +le # time error: *$e :ro, # the elements of @f are aliased to any remaining args, # i.e. a slurpy with aliasing ...: *@f # .. or a slurpy hash; every second remaining arg is aliased t +o # the hash's values: *%g ) { ... }

    Type and Value Constraints and Coercions

    sub f( $self isa Foo::Bar, # croak unless $self->isa('Foo +::Bar'); $foo isa Foo::Bar?, # croak unless undef or of tha +t class $a!, # croak unless $a is defined $b is Int, # croak if $b not int-like $c is Int?, # croak unless undefined or in +t-like $d is PositiveInt, # user-defined type $e is Int where $_ >= 1, # multiple constraints $f is \@, # croak unless array ref $aref as ref ? $_ : [ $_ ] # coercions: maybe modify the +param ) { ...};

    It seems that people express a desire to be able to write something like:

    sub f (Int $x) { ... }

    as a shorthand for for something like:

    sub f ($x) { croak unless defined $x && !ref($x) && $x =~ /\A-?[0-9]+\Z/; ....; }

    Similarly people want

    sub f (Some::Arbitrary::Class $x) { ... }

    as a shorthand for

    sub f ($x) { croak unless defined $x && ref($x) && $x->isa(Some::Arbitrary::Class); ...; }

    Furthermore, there are also Perl 6 generic constraints:

    sub f ($x where * < 10*$y) { ... }

    Scope and Ordering

    We need to determine and document how the various parts of a signature behave as regards to lexical scope, visibility, tainting and ordering of things like default expressions and constraints.

    dave_the_m proposes for lexical scoping that:

    sub f($a, $b, $c, ... ) { BODY; }

    Is logically equivalent to:

    sub f { my $a = ....; my $b = ....; my $c = ....; ....; BODY; }

    In particular, each parameter element is independent taint-wise, and each parameter variable has been fully introduced and is visible to default expressions and the like in further parameters to the right of it.

    Miscellaneous suggestions

    This last post contains are a few random suggestions that people have made at various times.

Custom date calculations using Date::Manip
No replies — Read more | Post response
by cavac
on Nov 27, 2019 at 12:57

    Some time ago, i uploaded Acme::September::Eternal to cpan. Then, on request by stevieb at Re^3: Help with my crap, i got a variant of that project.

    To quote: "I'm Canadian, so for us folk, it would be preferred if it was eternaldecemberize() where there's a single month of warm weather (August), and the rest December"

    I have uploaded Acme::December::Eternal to CPAN. But before that, i wrote a small test program to check out the math involved. The premise is that the year starts on 1st of August, and except of August everything else is the month of December. Let's take a look (you might need to click, i've put most of the article into a readmore tag)...

    Note: This is still technically incorrect, because there have been instances where countries skipped days on the calendar. For example, Samoa skipped the 30th of December 2011 so they could get to the other side of the dateline for some business reason. I'll have to fix my CPAN module to account for that kind of stuff.

    print $outstring, "\n";

    We output the calculated date string and we are done.

    Note 2: Calculating exact dates in the future is not possible, no matter how good your date library is. Not only for reasons like countries skipping (or adding) days, switching calendars, changing timezones on short notice or redefining daylight savings time (or banning/reintroducing it) willy-nilly after every change of government. No, even if you could fix all that (hint: go into politics), the nice folks at the International Earth Rotation and Reference System Service who keep our atomic clocks in sync with our solar system release a new Bulletin C twice a year to tell you if there is going to be a leap second at the end of the six month period. So, good luck estimating future timestamps ;-)

    perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
a lot of the CPAN big hitters have gone
3 direct replies — Read more / Contribute
by tobyink
on Nov 26, 2019 at 03:50

    I know I'm guilty of disappearing for extended periods myself. I understand that family, jobs, life can give people less time to contribute to open source projects. But it's somewhat concerning that a lot of major CPAN authors who have written some pretty useful modules seem to be disappearing lately. None of the following authors have made a release in the last 12 months:

    • ADAMK - Params::Util, DBD::SQLite
    • DOY - Eval::Closure
    • FLORA - Term::ReadLine
    • KENTNL - HTML::Tree
    • MSCHILLI - Log::Log4perl
    • MSCHWERN - Test::More, Method::Signatures
    • NUFFIN - KiokuDB, Try::Tiny
    • RCLAMP - File::Find::Rule, Pod::Coverage
    • RSRCHBOY - MooseX::AttributeShortcuts
    • STEVAN - Moose
    • TIMB - DBI, Devel::NYTProf
    • SIMONW - Module::Pluggable

    (Honorable mentions to INGY, DAGOLDEN, and RSAVAGE who have barely released anything in the last 12 months.)

    Many of their projects have gotten new maintainers, and there are always new CPAN authors coming up and releasing some great new things, but we do seem to be losing some key people who have made important contributions to the Perl ecosystem.

New berrybrew installer; Looking for testers
3 direct replies — Read more / Contribute
by stevieb
on Nov 22, 2019 at 13:45

    I recently had one of my clients ask me if I could automate installing berrybrew along with specific existing and new Perl instances.

    I've taken a couple of days to get things to the point where my release automation is doing the right thing. I've tested it on a half dozen Windows 10 VMs, and things appear to work correctly. That said, I probably have differing configurations on my Windows machines than others do, so I'm hoping I can get some volunteers to test it out and see if there are any oddities.

    The installer will install the 1.27 version, and is located right here.

    Defaults that should be visible throughout the process:

    • License should be displayed
    • Install directory should be "C:\Program Files (x86)\berrybrew"
    • "Install Perl 5.30.0_64" should be displayed as a component, and checked
    • You should see a couple of cmd windows open and close, then, if you've left the Perl install checkbox checked, a third cmd window will remain open displaying install progress. It should close upon completion

    After the install is complete:

    • echo %path% in a newly-opened cmd window should list "C:\Program Files (x86)\berrybrew\bin", and if you opted to install Perl 5.30.0 during install, you should see three paths all which should reflect "C:\berrybrew\5.30.0_64"
    • perl -V should be 5.30.0

    Uninstall: The uninstall program is inside of the install directory (by default, "C:\Program Files (x86)\berrybrew". After it's run, you should see (in yet another new cmd window:

    • Both the berrybrew path should be gone, as should all three of the Perl paths that were created
    • The "C:\Program Files (x86)\berrybrew" directory should remain, but be empty (I'm working on the removal of that dir)
    • The "C:\berrybrew" directory should still exist, and so should the 5.30.0_64 directory within it

    Re-installing after an uninstall will know if you've still got 5.30.0 installed and will bypass that part, but will "switch" to it before exiting.

    I'm also wondering if any UAC/security warnings or boxes pop-up during install.

    Thanks all!

    -stevieb

Perl Feels Good
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/
Moo and command line scripts
1 direct reply — Read more / Contribute
by boftx
on Nov 08, 2019 at 20:02

    Hello fellow monks! It is good to once again tread these hallowed halls after all these moons of moons.

    I have been a fan of modulinos (thanks Brian D'Foy!) for a long time now because of the advantages for testability. I have also been a fan of Moo for several years. And of course, like many others, I have combined both techniques with Getopt::Long. I have also been using a standard set of command line options such as "--debug" and "--help", with "--debug" defaulting true so "--nodebug" is required to turn it off.

    In an effort to reduce boilerplate and a lot of copy-and-paste I wrote a simple Moo role to handle the basics for me. I have since refined it with a proper test suite and POD and it has now been released as MooX::Role::CliOptions. I would greatly appreciated any feedback from my brothers and sisters of the Monastery on any and all aspects.

    I am well aware that there are other ways of doing this, including a couple of other modules on CPAN. I hope that some will find this new Role to be easier to use in some respects, as well as being more "Moo-ish".

    You must always remember that the primary goal is to drain the swamp even when you are hip-deep in alligators.
Mozilla IoT platform Perl wrapper
4 direct replies — Read more / Contribute
by stevieb
on Oct 31, 2019 at 18:35

    As many of you know, I've spent the last four plus years working on software that allows us Perl hackers to muck with the Raspberry Pi.

    Although the uptake is relatively small, it has been a very enjoyable experience for me providing this for the community, especially given that I've received welcome and helpful feedback, along with bug fixes and wonderful criticism throughout it all.

    Now, Mozilla is opening up their IoT Platform with both REST and WebSocket APIs for the masses. I've been following it for a little while to see where it goes.

    I've already thrown out the question on my Perl blog, but it means more to me to ask here on Perlmonks; would it be worth my time to ensure Perl has an interface to it?

    -stevieb


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 meditating upon the Monastery: (7)
    As of 2020-04-01 03:49 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      To "Disagree to disagree" means to:









      Results (186 votes). Check out past polls.

      Notices?