The Time::Local Trap

The localtime and gmtime built-in functions are interfaces to the POSIX functions for turning a Unix epoch timestamp into date-time components in either UTC or the system local time. When you want to go the other way, there's Time::Local.

Well, almost.

The localtime and gmtime functions have two quirks as compared to the date-time components humans might expect. The value it returns for the month is 0-indexed, ostensibly so that it can be used directly in a 0-indexed array of 12 month names, and the value it returns for the year is the number of years since the year 1900.

Perl Weekly Challenge 017: Ackermann Function and URL Parsing

Ackermann Function

A(m, n) = n + 1                  if m = 0
A(m, n) = A(m - 1, 1)            if m > 0 and n = 0
A(m, n) = A(m - 1, A(m, n - 1))  if m > 0 and n > 0

I know that Perl6 supports multisubs, but when I see a function definition of this kind, I always think Erlang, where you get pattern matching and multisubs by default. Here’s how it looks:

-module(ackermann).
-export([ackermann/2]).

ackermann(0, N) ->
    N + 1;
ackermann(M, 0) ->
    ackermann(M - 1, 1);
ackermann(M, N) ->
    ackermann(M - 1, ackermann(M, N - 1)).

Perl solution is a bit less straightforward.

Perl jam @Booking.com ML center

I just spotted this on Twitter.

Booking.com are hosting a "Perl Jam" event on Monday 29 July 2019, 6:00pm
at Azrieli Sarona Tower, Tel Aviv-Yafo Israel.

There are three speakers- so it looks like a great way to spend an evening rather than a full on conference.

Registration at: https://bookingcareerseventstelaviv.com/perl-meetup-booking-com-ml-center

Up, up and Away!

This week's perl weekly challenge was a lot of fun. First of all, challenge number 2 was a breeze. The challenge was to parse and print the components of a URL. That was easy...

Perl Weekly Challenge && Damian Conway

I have been a big fan of Damian Conway ever since I bought his book "Perl Best Practices". With the recent regular blog by him about various tasks from the Perl Weekly Challenge showed us really interesting aspects of the task. The one he blogged, Vigenère vs Vigenère last was really special about Vigenere Cipher. I must admit I didn't know half of what he shared in the blog. I wonder how many knew the Vigenere Cipher wasn't invented by Vigenere.

I think, I owe him a drink next time I meet, as per the English tradition. However, being a practicing Muslim, I can't offer drink, instead I would offer box of chocolates.

In the mean time, I am going to reserve space for him in the weekly blog by name "Damian Corner" where we would talk about his blog.

What else happening these days?

I try to keep myself busy during the week by writing short blogs. In the weekly series "Meet The Champion", we recently spoke to Adam Russell, the winner of Perl Weekly Challenge - 016.

I also blogged about the optional API task which we introduced recently. Check out how Neil Bowers took it to another level. Perl Weekly Challenge - Optional API Task.

Enjoy !!!

Perl Weekly Challenge # 17: Ackermann Function and Parsing URLs

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

Spoiler Alert: This weekly challenge deadline is due in several days from now (July 21, 2019). This blog post offers some solutions to this challenge, please don't read on if you intend to complete the challenge on your own.

Challenge # 1: Ackermann Function

The common Ackermann function, named after Wilhelm Ackermann, is defined recursively as follows:

A(m, n) = n + 1                  if m = 0
A(m, n) = A(m - 1, 1)            if m > 0 and n = 0
A(m, n) = A(m - 1, A(m, n - 1))  if m > 0 and n > 0

The function grows very rapidly even for relatively small input values, so you may not want to try to compute it for input values such as 5 and 6. You probably don't even want to try it with the first input parameter (m) larger than 3. It also does a very large number of recursive calls, so that it will tend to be very slow.

Using generate_series and daterange for fun and profit

Read it here!

P.S.: As it seems that the ironman perl blog aggregator is down, I (ab)use blogs.perl.org to alert you of my new posts..

BackupPC 4.3.1 release

BackupPC is a high-performance, enterprise-grade system for backing up Linux, WinXX, and MacOS PCs and laptops to a server's disk. BackupPC is highly configurable and easy to install and maintain.

Given the ever decreasing cost of disks and raid systems, it is now practical and cost effective to backup a large number of machines onto a server's local disk or network storage. This is what BackupPC does. For some sites, this might be the complete backup solution. For other sites, additional permanent archives could be created by periodically backing up the server to tape. A variety of Open Source systems are available for doing backup to tape.

BackupPC is written in Perl and extracts backup data via SMB (using Samba), rsync, or tar over ssh/rsh/nfs. It is robust, reliable, well documented and freely available as Open Source on GitHub.

This release contains several bug fixes.

Find out more at https://github.com/backuppc/backuppc/releases/tag/4.3.1

Super 30 - Anand Kumar

Some of you, who know me personally, knows my background and how I managed to reached London in 2000. For others, I belong to a state called Bihar, in India. I was born and raised in the city of Jamshedpur. A city built by Tata. Who Tata? They are well respected Industrial group.

I still remember, outside of Bihar, people don't treat us well if they know you are from Bihar. I can tell you from my own experience when I moved to Mumbai (Bombay) in the year 1997. Because of this, people from Bihar don't disclose their identity. Recently some parts of Bihar got separated and created a new state "Jharkhand". In the process, Jamshedpur now belongs to newly created state Jharkhand. However, I still feel my roots belong to Bihar. It gives me immense pride when I hear nice thing about Bihar.

The Perl Conference in Riga

Short version: I'll be there.

Long version: people have been asking me why I've not been as visible in the Perl community as I used to be (including at least one person asking if I was still involved in Perl). Well, that's a long story.

Vigenère vs Vigenère

The second task of the 15th Perl Weekly Challenge was to implement
an encoder and a decoder for the Vigenère Cipher. But that’s a
little more complicated than it seems, because the cipher that's named
after Blaise de Vigenère wasn’t actually invented by him, and the cipher
that Vigenère actually invented isn’t named after him.

So should we implement the Vigenère Cipher...or Vigenère’s cipher?
Why not both!

The Vigenère Cipher was devised by Giovan Battista Bellaso in 1553,
and then misattributed to Vigenère about three hundred years later.
It uses a tabula rēcta to translate from a message text to a ciphertext,
and back again.

Given an user-provided key (e.g. "BELLASO"), we encipher a message
(e.g. "VIGENEREDIDNOTINVENTTHIS") by matching up respective letters of the
key and message, then using them as two indices to look up the corresponding
cipher character in the appropriate column and row of the tabula rēcta.
And if the key is shorter than the message, we just recycle the key
as many times as necessary.

For example:

Perl Weekly Challenge 016: Pythagoras Pie Puzzle and Bitcoin Address Validation

Pythagoras Pie Puzzle

At a party a pie is to be shared by 100 guest. The first guest gets 1% of the pie, the second guest gets 2% of the remaining pie, the third gets 3% of the remaining pie, the fourth gets 4% and so on. Write a script that figures out which guest gets the largest piece of pie.

I started with a straightforward implementation of the specification. Start with the pie of size 1; in each step, find out the size of the corresponding guest’s part, remember it if it’s largest one so far, and decrease the size of the pie.

Pizza Party for 100

Hi all, this is my first blog post! Yay!

Now that that's out of the way, I'd just like to go over my solution for this week's Perl weekly challenge.

The first challenge was to divide a pie between 100 people, in a manner where the first guest gets 1/100 (i.e. 1%) of the pie, and the second gets 2/100 (i.e. 2%) of what remained, etc etc. The question is, who got the biggest piece of pie.

If I were better at math, I would prove that the answer is the square root of the amount of guests, because that does seem to be the case. Since I'm not, I solved it procedurally, as follows.

We set up our guests. We allow for the user to pass in a value on the command line, to check values other than 100, but default to 100:

use v5.22; #that's my perl
my $guests = shift // 100;

Perl Weekly Challenge # 16: Bitcoin Addresses

In this post dated July 8, I provided solutions to the first challenge of Week 16 of the Perl Weekly Challenge organized by Mohammad S. Anwar. At the time, I admitted that I was having trouble understanding the requirement for the second challenge. After quite a bit of googling, I can finally provide some answers to the second challenge of Week 16.

I should acknowledge that I spent far more time on this than I would wish to admit. Far more time than I ever did on any of the previous challenges.

Validation of Bitcoin Addresses

Perl Weekly Challenge #016

Task #1: Pythagoras Pie Puzzle

This puzzle’s connection with Pythagoras is tenuous indeed: it originally appeared in the Dutch magazine Pythagoras (see here and here)! But the puzzle is interesting. Of course, the real challenge is to work out the answer mathematically, but for those of us who are mathematically declined a Perl script is the way to go.

The first draft of my solution was tied to the 100 guests specified in the puzzle statement, but it’s easy to extend the puzzle to allow any (positive integer) number of guests. So I include the number of guests as a constant $GUESTS and the central calculation becomes:


$piece = ($guest / $GUESTS) * $pie;

where $guest is any number in the series 1 .. $GUESTS and $pie is the fraction of original pie remaining at this point in the distribution.

Perl 5 solution

For my own interest I added code to display the size of each guest’s piece of pie. This code can be omitted from compilation by setting DEBUG to a false value.

File ch-1.pl

RPerl at the Perl Conference in Pittsburgh - Day 3

Howdy!

We're back for the final day of the Perl Conference. Wendy and Liz were very much missed this year, but we had enough Perl items to set up a booth, with the help of Ruth Holloway and Peter Sargent. The table was full of buttons, stickers, tuits, and other info from Perl Careers.

On this final day we attended the traditional Q&A with Larry Wall. People were able to send their questions via Twitter, and I asked Larry who his favorite musical composer is.
I'm not a technical person, but I am a violinist, which gives me something in common with Larry Wall! Pretty cool, right? Anyway, Larry's answer was Gustav Mahler. Very good answer Larry, I myself am a Mahler enthusiast. What I remember from this Q&A session is Larry's call for peace and respect. The Perl community has a lot of great people, very different from one another. The things we have in common should always surpass our differences.

Next stable DBD::SQLite will be released in the mid-August

DBD::SQLite 1.63_05 (with SQLite 3.29.0) is a release candidate for the next stable DBD::SQLite. There are no big changes, maybe except for two new db_config options to disallow double-quoted string literals.


  use DBD::SQLite::Constants qw/:database_connection_configuration_options/;

  $dbh->sqlite_db_config( SQLITE_DBCONFIG_DQS_DML, 1 );
  $dbh->do('INSERT INTO foo VALUES (1, "text")'); # Now this is an error


I'll wait for about a month as always, and release 1.64 in the middle of August (that means, after PerlCon) if there's no blocker nor request to wait for more. Thank you for your patience.

Infinite work is less work


The first task of last week's Perl Weekly Challenge was to print the
first ten strong and weak primes. A prime pn is "strong" if it's larger
than the average of its two neighbouring primes (i.e. pn > (pn-1+pn+1)/2).
A prime is "weak" if it's smaller than the average of its two neighbours.

Of course, this challenge would be trivial if we happened to have a list
of all the prime numbers. Then we'd just filter out the first ten that
are strong, and the first ten that are weak. In fact, it would be even
easier if we happened to have a list of all the strong primes, and a
list of all the weak ones. Then we'd just print the first ten of each.

But there are an infinite number of primes and of weak primes (and
possibly of strong primes too, though that's still only conjectured)
,
so building a complete list of the various subspecies of primes
is impractical in most programming languages.

Draw a hexagon and fill it with color using Imager

Draw a hexagon and fill it with color using Imager

Source code.

RPerl at the Perl Conference in Pittsburgh - Day 2

Day 2 of the Perl Conference, and I am now a seasoned volunteer! I know all about HDMI recorders and cameras - well, almost…

This second day saw the very first meeting of the Perl Mongeresses, a Birds-Of-a-Feather for women in the Perl community. This year’s Perl Conference was notable for the highest known attendance of women to The Perl Conference ever! By highest, I mean… about 15 ladies total. Yes, there’s still work to do. This meeting was the opportunity to discuss issues that women are facing in the programming world.

Thank you, Ruth Holloway, for the Perl Mongeress initiative! I’m looking forward to the second edition next year. If some of my female readers plan to attend the PerlCon in Riga next month, you still have time to add one to the BoFs...

About blogs.perl.org

blogs.perl.org is a common blogging platform for the Perl community. Written in Perl and offering the modern features you’ve come to expect in blog platforms, the site is hosted by Dave Cross and Aaron Crane, with a design donated by Six Apart, Ltd.