Paws XXXXIII (More fun with XML)

he first order of the day was to clean up all the debugging code I peppered across my perl trying to find an answer to my 'Failed Signature' bug.

This did take a while and in the end the changes that I am sticking with are;



  if ( my $xml_body = $self->_to_xml_body($call) ) {
        $request->content($xml_body);
++      $request->header( 'content-type' => 'application/xml');  #this is an XML interface so it should have this header
     }
and

Perl Weekly Challenge 039: Guest Book and Reverse Polish Notation

Guest Book

A guest house had a policy that the light remain ON as long as the at least one guest is in the house. There is guest book which tracks all guest in/out time. Write a script to find out how long in minutes the light were ON.
1) Alex    IN: 09:10 OUT: 09:45
2) Arnold  IN: 09:15 OUT: 09:33
3) Bob     IN: 09:22 OUT: 09:55
4) Charlie IN: 09:25 OUT: 10:05
5) Steve   IN: 09:33 OUT: 10:01
6) Roger   IN: 09:44 OUT: 10:12
7) David   IN: 09:57 OUT: 10:23
8) Neil    IN: 10:01 OUT: 10:19
9) Chris   IN: 10:10 OUT: 11:00

Default value expression in subroutine signatures

In first proposal of subroutine signatures, default value is the following.

sub func($foo //= 0, $bar ||= 0) {
  
}

I think this can use only "=" as same as many ohter languages. and "||" is in body if needed.

sub func($foo = 0, $bar) {
  $bar ||= 0;
}

Default value expression - subroutine signatures opinion blog

Perl Weekly Challenge 59: Linked Lists and Bit Sums

These are some answers to the Week 59 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few hours. This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Linked List Partition

You are given a linked list and a value k. Write a script to partition the linked list such that all nodes less than k come before nodes greater than or equal to k. Make sure you preserve the original relative order of the nodes in each of the two partitions.

For example:

Linked List: 1 → 4 → 3 → 2 → 5 → 2

k = 3

Expected Output: 1 → 2 → 2 → 4 → 3 → 5.

Paws XXXXII (A little help from my friends)

Now that I have at least one call working 'ListJobs' I reran the full test suit and to my surprise I got no fails. So maybe it is going to be an easy ride?

Well I was dead wrong.

Just spent the last few days banging my head against the AWS servers thinking that if the first 825 attempts to get 'CreateJob' to work, the 826th would of work.

I think I got sucked into the gambler's fallacy.

Well lets just say 826 attempt is most likely an order of magnitude under the number of differing combinations and iterations I went though on getting the call working all with the same failed of '403' status and the error 'SignatureDoesNotMatch'!

The times you want to avoid the short cuts. PWC-39

No spoilers here, just a rambling. There are probably countless times when one relies on the genius of others to complete tasks. If PerlWeeklyChallenges has shown me one thing, it is that there is probably nothing I can do that someone else can not do better, more efficiently, and more robustly. The key to good coding, one imagines, is to have code that survives not just the scenario presented in the challenge, but also accommodates other scenarios

The Hotel lights

Take the lights on puzzle. A first glance at the puzzle show that the times are all overlapping, so technically the lights should be on continuously from the first guest entry to last exit. So the simplest way to extract the time the lights were on is to get the earliest time and the latest time mentioned in the log. These can be extracted using four steps: load the log, extract the earliest and the last time; convert to minutes and subtract.

It's beginning to look a lot like k-Means 🎵

... every where you go!

Continuing on from the intention of clustering data in Perl (a form of unsupervised learning), I'm going to start with PDL::Stats::Kmeans and see how far I can get.

Let's just plunge in and use the module and read the documentation after to figure out what it all k-means. (sorry)

# Perl Weekly Challenge 58: Compare Versions and Ordered Lineup

These are some answers to the Week 58 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (May 3, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Compare Versions

Compare two given version number strings v1 and v2 such that:

- If v1 > v2 return 1 - If v1 < v2 return -1 - Otherwise, return 0

The version numbers are non-empty strings containing only digits, and the dot (“.”) and underscore (“”) characters. (“” denotes an alpha/development version, and has a lower precedence than a dot, “.”). Here are some examples:

The way that CPAN authors use subroutine signatures in natural

Perl's new feature is for the new Perl, but when it comes to subroutine signatures, CPAN Author also maybe wants to use it.

If CPAN authors can use subroutine signatures, both application code and CPAN module code can be written in one source.

I think new features should work with the new Perl, but I'm happy that only the subroutine signature feature can be backported.

Wouldn't it be nice if you could use subroutine signatures with tens of thousands of CPAN modules?

But is there such a way?

The way that CPAN authors use subroutine signatures in natural

Long time no see

Paws XXXVII (So close but yest so far)

Well I was just about ready to check everything in on S3 Paws and move onto the next part of Paws that need some love and kindness when I did one last review of all the test cases I have created over the past little while when I discovered I had left one out.

I forgot to add in a request test case for the 'DeleteBucketMetricsConfiguration' action. It took the opportunity to use my new test generator a spin as well so I fired up my real world call with the new caller and much to my chagrin I got an error;

'The specified configuration does not exist.',

Which could be the case as the Bucket I was playing with may not have a 'Metrics Configuration' on it. So I dusted off another test that does both 'PUT and 'GET' and then I slapped my 'DELETE' on the end and this was the result;

Perl Weekly Challenge 57: Tree Inversion and Shortest Unique Prefix

These are some answers to the Week 57 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of hours. This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Tree Inversion

You are given a full binary tree of any height, similar to the one below:

    1
   /  \
  2    3
 / \  / \
4   5 6  7

Write a script to invert the tree, by mirroring the children of every node, from left to right. The expected output from the tree above would be:

Is the new grammar easy to google search?

Is the new grammar of subroutine signatures easy to google search?

One of the criticisms of Perl is that "it cannot search google because it has many symbols".

Increasing the number of difficult-to-search symbols also increases the blame for Perl.

Is the new grammar easy to google search?

Can't post a comment here -- dunno why

Why, oh why, can't I post a comment on blogs.perl.org? I'm properly signed in. I read a post, 30 seconds later. 30 seconds later, I click the button at the bottom of the post in order to post a reply. I fill in the form with my post. Then I get this error:

---

Comment Submission Error

Your comment submission failed for the following reasons: Your session has expired. Please sign in again to comment.

Return to the original entry.

---

And there is no avoiding it, even after signing in again.

Thanks very much for any help you can provide.

Rewriting Perl Code for Raku Part V is out

Part V of the series is out, this time more in-depth discussions of the pack() method in Raku and Perl

Perl Weekly Challenge # 56: Diff-k and Path Sum

These are some answers to the Week 56 of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a couple of days (April 19, 2020). This blog post offers some solutions to this challenge, please don’t read on if you intend to complete the challenge on your own.

Task 1: Diff-k

You are given an array @N of positive integers (sorted) and another non negative integer k.

Write a script to find if there exists 2 indices i and j such that A[i] - A[j] = k and i != j.

It should print the pairs of indices, if any such pairs exist.

Example:

@N = (2, 7, 9)
$k = 2

Output : 2,1

New Role Of Roles In Raku

My morning started today with a cup of cold tea and an IRC request. The latter was coming from Elizabeth Mattijsen asking to write a paragraph on my recently merged work on Raku roles. There was a little problem though: I have no idea how to fit it into a single paragraph! And so I was left with no choice but to start blogging for the first time in many years.

Note. For those of you who consider themselves Raku experts I'd rather recommend skipping the next two sections and proceed directly to the technical details in Changes.

Once upon a time...

... there was a project which I was implementing to support a my boss' project. The structure of the code was heavily based on roles. This is the pattern I tend to use: split functionality into manageable as small as possible pieces and compose them into final code.

Of course, roles fits the pattern perfectly...

A Static Archive of use.perl.org

In my previous post I added a footnote that "use.perl.org is difficult to get info out of now, it's basically dead. A lot of content is lost". That turned out to be not entirely true, it just needed some work to get to it

In the reddit comments, brian d foy mentioned Léon's WWW::UsePerl::Server, a module to host the use.perl.org archive.

I grabbed the archive, Léon's module, installed all the deps, got it up and running after hacking the module to work with the latest Catalyst, then combined some sed, awk, perl, SQL to create a static version of the site with URLs that allow it to function correctly: https://use-perl.github.io/. Note that the change in the URL structure to get it to work a) as a static site, and b) on github pages, means that any "permalinks" that might exist elsewhere in reference to it will need manual fiddling to get to the page in question - the URL structure should be relatively obvious however.

Risk increased by checking the number of subroutine arguments

The current subroutine signature specification checks the number of subroutine arguments.

On the other hand, there is actually risks of increasing by checking the argument count.

Risk increased by checking the number of subroutine arguments - Perl Subroutine Signatures Opinion Blog

Revisiting the Collatz Sequence (PWC 54)

In my blog post related to Perl Weekly Challenge 54 posted on April 4, 2020, the section about the "extra credit" task concerning the Collatz conjecture described in some details the difficulties encountered when trying to cache the data: the volume of data is very large. I'm blogging again on the subject because of new findings.

The Collatz conjecture concerns a sequence defined as follows: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half of the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. For example, the Collatz sequence for 23 is this:

23 70 35 106 53 160 80 40 20 10 5 16 8 4 2 1

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.