Perl Weekly Challenge 98: Read N-Characters and Search Insert Position

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

Task 1: Read N-characters

You are given file $FILE.

Create subroutine readN($FILE, $number) that returns the first n-characters and moves the pointer to the (n+1)th character.

Example:

Input: Suppose the file (input.txt) contains "1234567890"
Output:
    print readN("input.txt", 4); # returns "1234"
    print readN("input.txt", 4); # returns "5678"
    print readN("input.txt", 4); # returns "90"

Read N-characters in Raku

This is my first attempt:

You think you're an X, but you're only a Y

The other day I was converting the output of a Git::Raw::Commit into JSON using my module JSON::Create, when I noticed an oddity:

{
"commits":[
    {
        "body":null,
        "id":"27ed4669e32ce2d14831c719dfd5b341a659788e",
        "message":"Remove a stray html ending tag\n",
        "time":"1609997818"
    },

The "time" part always comes out as a string, even though it's clearly a number. Was this a bug in my module, some kind of dual-string-and-number wannabee variable which JSON::Create falsely turned into a string?

CY's Take on PWC#094

If you want to challenge yourself on programming, especially on Perl and/or Raku, go to https://perlweeklychallenge.org, code the latest challenges, submit codes on-time (by GitHub or email).

Do tell me if I am wrong or you strongly oppose my statements!

Task 1 of #094 looks like a sibling of Task 1 of #092 (which Perl codes are recently reviewed, my submitted code here) and Task 2 of #094 looks like a sibling of Task 2 of #093 (where I use the array representation of binary tree, code here).

Task 1: Group Anagrams

Now I was thinking of CJK characters. When comparing terms, put -CA; and inside scripts, put use utf8; use open ':std', ':encoding(UTF-8)';.

And my approach is similar to that of Week #092. On #092, a sub learn_pattern produces a hash from the first parameter; and sub verify_pattern for the second parameter returns true or false. Now, this time we face a bulk of terms, therefore we have to &collect_alphabets: [1]

SanDiego.pm Meeting, Tuesday, January 12th, 2021

This is your friendly reminder that the SanDiego.pm quarterly meeting will be this Tuesday, January 12th, starting at 7 PM PST. As has been the case for the last several meetings, we'll be meeting again on Zoom (details below).

Topics for the meeting include Perl (of course), COVID-19, CentOS, and anything else that people would like to talk about.

Perl Weekly Challenge 97: Caesar Cipher and Binary Substrings

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

Task 1: Caesar Cipher

You are given string $S containing only the letters A..Z and a number $N.

Write a script to encrypt the given string $S using a Caesar Cipher with left shift of size $N.

Example:

Input: $S = "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG", $N = 3
Output: "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD"

Plain:    ABCDEFGHIJKLMNOPQRSTUVWXYZ
Cipher:   XYZABCDEFGHIJKLMNOPQRSTUVW

Plaintext:  THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
Ciphertext: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD

ABC Mart

800px-ABCMART_Minamisomaharamachi_Shop.jpg

One thing which I like about Mojolicious is that they put all the functions and methods in alphabetical order. When you get used to that then go back to a module like Git::Raw::Repository with a large number of functions in apparently random order, it does seem like quite a smart move for the reader to use the alphabetical ordering.

Anyway I thought so, so I've been putting all the functions, methods, and other things in my modules into alphabetical order. I even started to write tests that they are all alphabetical, since I usually manage to slip up on these things.

Let us Have a Productive Year of 2021

pusheen.jpg

Bye, 2020

There are 28 entries on this blog in the Year 2020.

In February, I started to join "The Weekly Challenge"(PWC in short, as initially it was called "Perl Weekly Challenge" while the name "Perl6" hadn't been replaced by Raku). Then I slowly involved in the Perl community as a beginner.

At first, my codes were messy! I have forgotten from where I heard of Perl Best Practices(by Damian Conway; btw, I have to revisit it again), but have been trying to adopt some of its pieces of advice as many as possible. And then I read more codes and decided to maintain my code more modularized and structured; in addition, I have learnt to use the unit testing package in Perl (thanks to Perl Monks).

Annual Report - 2020

Lets wipe out the memory of 2020

Am I bitter about 2020?

No, not at all. I like to find happiness in every little things in life. It is an art that I am still learning. I am writing this as a part of my monthly routine sharing last month activities. However this is special as it also has overall annual report of the year 2020.

I am embarassed looking back what I had planned at the start of the year.

Do I have any plan for 2021?

No way, I am not going to repeat my mistake. For a change, I want to see how I deal with my life without any plan.

Perl Weekly Challenge 96: Reverse Words and Edit Distance (and Decorators in Perl)

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days (January 24, 2021). 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: Reverse Words

You are given a string $S.

Write a script to reverse the order of words in the given string. The string may contain leading/trailing spaces. The string may have more than one space between words in the string. Print the result without leading/trailing spaces and there should be only one space between words.

Example 1:

Input: $S = "The Weekly Challenge"
Output: "Challenge Weekly The"

Example 2:

Input: $S = "    Perl and   Raku are  part of the same family  "
Output: "family same the of part are Raku and Perl"

Reverse Words in Raku

I'm Making Headway Now

Last January there was a post on reddit which claimed that my module JSON::Parse was not only failing some of the JSON Test Suite tests, but also crashing on one of them. Anyway I should have got around to doing something about it sooner, but here are my conclusions.

First of all there was a crash on one of the files, which went something like this: [{"":[{"":[{"", repeated about 100,000 times. (The actual file is here if you really want to see it.) Investigating it using a LInode, I found that after 80,000 open brackets the stack was overflowing, causing the crash to occur. If I added a printf in the midst of my code the printf would cause the stack overflow, so it wasn't actually due to my code but just because the stack size seems to be quite small on Linux.

First Perl Steering Council elected to replace Pumpking position

The most important Perl Governance poll yet has concluded. The position of Pumpking is no more, and is instead now held by a shared 3 person Steering Council, as defined in perlgov.pod: https://github.com/Perl/perl5/pull/18357/files

To quote RJBS:

Perl has two well-defined bodies involved in its governance: a core team of a few dozen and a steering council of three people. The core team sets the rules of Perl governance, votes on membership of the two groups, and delegates substantial decision making power to the steering council. The steering council has broad authority to make decisions about the development of the Perl language, the interpreter, and all other components, systems and processes that result in new releases of the language interpreter. Right now, the core team has 25 members, although this may change over time.

The new Perl Steering Council is now:

RJBS + Neil Bowers + Sawyer X

Thanks to all of them for stepping up and donating their efforts to the Perl community. :)

Further information on these matters can be found on the p5p mailing list and the public perl core mailing lists.

Perl dying? Well now I don't care

It is a bit of a long story how I got burned by bad perl internal politics.

For many years I wanted images in Pod. And many others wanted too. And of course, each time I raised this in lists and on facebook, an answer was, if you want it, go and write it yourself. I would tell that myself, the classic "patches are welcome". Until one day I said, well, now, why actually not, right? Especially that I do have experience in creating and actively using images in pod using various hacks, such as direct inclusion of html with images, and even writing a standalone POD viewer capable of showing said images.

Perl Weekly Challenge 95: Palindrome Numbers and Demo Stack

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

Spoiler Alert: This weekly challenge deadline is due in a few of days (January 17, 2021). 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: Palindrome Numbers

You are given a number $N.

Write a script to figure out if the given number is Palindrome. Print 1 if true otherwise 0.

Example 1:

Input: 1221
Output: 1

Example 2:

Input: -101
Output: 0, since -101 and 101- are not the same.

Example 3:

Input: 90
Output: 0

The Twelve Days of Dancer, 2020 Edition

Need some joy this holiday season? Head over to the Dancer Advent Calendar for this year's Twelve Days of Dancer. With a little help from our friends, we've put together a 12-day mini advent calendar featuring some great software built in Dancer, some helpful tips and tricks, new features, and more.

Thanks for being such a great community, and for your continued support of Dancer! Wishing you the happiest of holiday seasons!

CromeDome (on behalf of the Dancer Core Developers)

Bill & Ted's Bogus Journey

Most operating systems have a version of libpng, the library for reading and writing the PNG (portable network graphics) image format on them. Unfortunately, though, the libpng is often fairly old.

I wrote a CPAN module which links against libpng, but then trying to get the module tested with CPAN testers, a lot of bugs would happen. It was frustrating because I couldn't work out what was going wrong with the tests unless I could find out what version of libpng was installed on the testing machine.

The solution I came up with in the end was a bogus test file which merely prints the libpng version as its skip_all message. This turned out to be quite effective in working out what is going wrong as various improvements to my PNG module turn out to trip bugs in older versions of libpng.

Strawberryperl.com - https any time soon?

Throwing this one out to the wider community, if anyone can assist in adding https support to strawberryperl.com that'd be great, with browsers and corporate firewalls moving towards a stricter mode of operation. An existing issue is here, with some history for those interested. Thanks in advance.

Perl Weekly Challenge 94: Group Anagrams and Binary Tree to Linked List

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

Spoiler Alert: This weekly challenge deadline is due in a few of days (January 10, 2021). 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: Group Anagrams

You are given an array of strings @S.

Write a script to group Anagrams together in any random order.

An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.

Example 1:

Input: ("opt", "bat", "saw", "tab", "pot", "top", "was")
Output: [ ("bat", "tab"),
          ("saw", "was"),
          ("top", "pot", "opt") ]

Example 2:

Input: ("x")
Output: [ ("x") ]

From a Reflection on The Weekly Challenge 092 Task 1

Update: Ben Bullock has provided script for my question.
See the comment section. Thanks Ben.

---------------------

Happy New Year!


Today's data is about

$ perl pwc092-1_isomorphic.pl '茫茫人海' '夜夜笙歌'
0

--

Seeing others' post, I have a short reflection on dated The Weekly Challenge #092 Task 1 (statements / recap ), but may lead to a hike towards a hill in Perl.

Task statement:

TASK #1 › Isomorphic Strings Submitted by: Mohammad S Anwar

You are given two strings $A and $B.

Write a script to check if the given strings are Isomorphic. Print 1 if they are otherwise 0.
Example 1:

Input: $A = "abc"; $B = "xyz"
Output: 1

Example 2:

Input: $A = "abb"; $B = "xyy"
Output: 1

Example 3:

Input: $A = "sum"; $B = "add"
Output: 0


My unsatisfactory code (distaste due to the two subroutines &verify_pattern and &learn_pattern are almost the same).

Suddenly today I want to try out whether the Unicode support is direct; sadly, no:

For a single character:

Misusing newSVpv

I managed to cause another set of obscure bugs by misusing newSVpv. The goal of this code is to split the RGB and the alpha (transparent) part of a PNG image, for the use of the PDF::Builder module on CPAN.

Here the SV in newSVpv is "scalar value", and the "pv" means "string". My code says this:

sv = newSVpv ("", len);

and it causes the crash on Solaris and other operating systems because the above statement is a bad idea. What happens is that Perl copies "len" bytes from my string, where "len" might be a very large number, for a large PNG image, but I've given it the string "" to copy from. So Perl tries to copy from uninitialised, or possibly even inaccessible, parts of the computer's memory. I found out my error only after almost giving up, by using valgrind to look for memory errors.

The correct version of this is

Development community that we can see to development of Perl Part1 - C language specification creating group

The Perl core team seems to be looking for resources to help in language development.

Currently, it seems the material in python.

perlgov: the perl governance document

I feel that Perl and Python cultures are quite different.

It's also based on an improvised document in 2019 when the Python reader quit.

I can understand how envious we are when we see Python attracting users(although
I'm watching a lot of cheating at the same time).

On the other hand Perl has long been a conservative culture.

So, we can refer to the methods used by developers of languages, operating systems and tools that also have a conservative mindset.

The first thing I would like us to refer to is the method used by the group that creates C language specifications.

C language specification creating group

C89, C99, C11

Development of C language has continued some slowly, but functions that users think are lacking have been added.

Specially C99 is added good features I wanted.

It would be worthwhile to ask the C specification group how it was achieved.

I think it's less repulsive and less likely to fail if we adopt a method from a culture similar to Perl rather than a culture opposite to Perl.

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.