Perl Weekly Challenge 185: MAC Address and Mask Code

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

Task 1: MAC Address

You are given MAC address in the form i.e. hhhh.hhhh.hhhh.

Write a script to convert the address in the form hh:hh:hh:hh:hh:hh.

Example 1:

Input:  1ac2.34f0.b1c2
Output: 1a:c2:34:f0:b1:c2

Example 2:

Input:  abc1.20f1.345a
Output: ab:c1:20:f1:34:5a

MAC Address in Raku

This is done in a hurry, less than 45 minutes before the deadline. There might be a better or simpler way to solve this task, but using a couple of regexes is so simple that I don’t see any reason to try something else.

My Favorite Warnings: uninitialized

This warning was touched on in A Belated Introduction, but I thought it deserved its own entry.

When a Perl scalar comes into being, be it an actual scalar variable or an array or hash entry, its value is undef. Now, the results of operating on an undef value are perfectly well-defined: in a nuneric context it is 0, in a string context it is '', and in a Boolean context it is false.

The thing is, if you actually operate on such a value, did you mean to do it, or did you forget to initialize something, or initialize the wrong thing, or operate on the wrong thing? Because of the latter possibilities Perl will warn about such operations if the uninitialized warning is enabled.

If you really intended to do this, no warnings 'uninitialized'; will suppress the error.

Util::H2O ~ Iterative Refinement of Existing Perl Code

Util::H2O is an incredibly powerful tool for managing HASH references in a more natural way.

This post is the first of several that will explore this awesome module. I've started using it quite a bit in both new code and in existing code. There are several imporant cases where it really shines. Here we explore the power it has to iteratively refine existing code. It's also fun and easy to introduce into existing code.

Util::H2O provides a method called h2o that provides a very powerful way for turning a hash reference to an object . Generally speaking, this means I get accessors with as few keystrokes as possible.

I've been using this module quite a bit recently, and I really do like the improvements it has over the more traditional modules used for generating accessors.

The most basic use of h2o is to provide accessors to a hash reference with a single level of keys. I tend to use hash references a lot .

SPVM 0.9014 Release - add class, method, static keyword, omit SPVM:: namespace

I release SPVM 0.9014. Latest releases have some big changes.

add class, method, static keyword, omit SPVM:: namespace, and remove sub, self, keyword.

Before

Perl Weekly Challenge 184: Sequence Number and Split Array

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

Spoiler Alert: This weekly challenge deadline is due in a couple of days from now (on Oct. 2, 2022 at 23:59). 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: Sequence Number

You are given list of strings in the format aa9999 i.e. first 2 characters can be anything ‘a-z’ followed by 4 digits ‘0-9’.

Write a script to replace the first two characters with sequence starting with ‘00’, ‘01’, ‘02’ etc.

Example 1

Input: @list = ( 'ab1234', 'cd5678', 'ef1342')
Output: ('001234', '015678', '021342')

Example 2

Input: @list = ( 'pq1122', 'rs3334')
Output: ('001122', '013334')

Sequence Number in Raku

Monthly Report - August

Finally enjoying again ...

Ever since I joined Oleeo, I keep talking about it in every monthly report.

Why?

Well, right from day one, I have been getting to work on something I never worked on before. To be honest with you, I was expecting to fight with good old CGI ridden code mostly. I find myself lucky to have such a great supporting team. Right now I am playing with Elastic Search and I am enjoying it. Thanks to CPAN for such a cool library, Search::Elasticsearch.

Did you notice last monthly report was published on 22nd Aug?

I have never been so late ever since I started the series of monthly report.

You must be thinking, why bother with monthly report? Who cares what I do?

I agree, nobody cares. But I still do it every month since Nov 2018, my first monthly report was published on 2nd Nov 2018. In two months time, I would complete 3 years of monthly reporting. Honestly speaking, I didn't realise it until now.

My Favorite Warnings: redundant and missing

The redundant and missing warnings were added in Perl 5.22 to cover the case where a call to the printf or sprintf had more (redundant) or fewer (missing) arguments than the format calls for. The documentation says that they may be extended to other built-ins (pack and unpack being named specifically) but as of Perl 5.34.0 only the printf() built-ins are covered.

I have (very occasionally) found myself writing a subroutine taking a printf-style format and some arguments, and letting the format specify which (if any) of the arguments actually appear in the output. If I just throw all the arguments after the format into the printf(), one of these warnings is very likely to be thrown, starting with 5.22, since use warnings; enables them by default.

How to show UTF-8 at the Windows command prompt

If you windows Perl user, It is good to know How to show UTF-8 at the Windows command prompt .

How to show UTF-8 at the Windows command prompt

One liner is yet buggy, however UTF-8 showing is good in Windows command prompt.

Perl Weekly Challenge 182: Unique Array and Date Difference

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

Task 1: Unique Array

You are given list of arrayrefs.

Write a script to remove the duplicate arrayrefs from the given list.

Example 1

Input: @list = ([1,2], [3,4], [5,6], [1,2])
Output: ([1,2], [3,4], [5,6])

Example 2

Input: @list = ([9,1], [3,7], [2,5], [2,5])
Output: ([9, 1], [3,7], [2,5])

Unique Array in Raku

The Raku solution is essentially a one-liner (more than one line because of the tests). We convert the sub-arrays into strings and use the unique built-in routine to remove duplicates.

TWC 127: Intersection on a Sunday Afternoon

This is my entry for

The Weekly Challenge, week 127

Task 1, "Disjoint Sets" was basically something I've done before somewhere else. In fact, what I'm using is overkill for just determining if two sets intersect. I imagine most people would probably use the FAQ answer. However, I'm a fan of what cardinal LanX of Perl Monks fame was trying to do in making set intersection a more "organic" operation. I don't know how much those ideas developed, however, so I'll be looking at the other solutions to see if there's anything new.

I actually did use my perlmonks code on real problem a few years ago, in modified form. It does the trick pretty quickly compared to other approaches. Thanks perl hashing!

You can find my code for Task #1 here.

Monthly Report - July

Never been so busy ...

The guilt is killing me every time I delay the monthly report. I finally found time to get this out on 22nd day of the month where I would do that on the very first day of the month in the past.

Life can be challenging at times, balancing personal and professional aspect can be difficult, I must confess.

In all of these up and down, I have to keep myself motivated and find ways to stay happy.

I try to avoid negative thoughts coming on my way and stay positive.

Object::Pad review Yuki Kimoto's 2021-08-21 - Constructor default argument

I start to review Paul Evans's Object::Pad from my personal thinking.

Latest years, Perl core teams positively try to implement Object-Oriented feature to Perl core. I hope my review helps a little.

First time is constructor default arguments.

Perl Weekly Challenge 182: Max Index and Common Path

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on Sept. 18, 2022 at 23:59). 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: Max Index

You are given a list of integers.

Write a script to find the index of the first biggest number in the list.

Example:

Input: @n = (5, 2, 9, 1, 7, 6)
Output: 2 (as 3rd element in the list is the biggest number)

Input: @n = (4, 2, 3, 1, 5, 0)
Output: 4 (as 5th element in the list is the biggest number)

Max Index in Raku

A dream realized

Have you heard that they are finally putting together a proposal to add a clean modern OO system into the core of Perl?

If you haven’t, I strongly encourage you to look over the RFC for Corinna, or at least watch Ovid’s excellent presentation on the project.

It’s reassuring that the list of contributors to the proposed design includes some of the most highly respected names in the Perl community, many of whom have previously taken one (or more!) tilts at this particular object-oriented windmill.

Indeed, over the past two decades I too have repeatedly attempted to design and prototype richer and more robust OO systems for Perl, starting way back in the previous millennium with a brief stint as the maintainer of Class::Struct, and continuing on though the release of modules such as Class::Std, Class::Delegation, and most recently: Dios.

Making Taint support optional in Perl

One of the changes to Perl that we're considering on p5p (the perl5-porters mailing list) is the removal of taint support. The first step towards that is to add a Configure option that lets you build a Perl without taint support.

In this post I'll explain what we're considering, and why. The purpose of this post is to let everyone beyond p5p know about this, and give you a chance to comment.

TWC 124: Literalism and existence proofs in the service of stress reduction

Again another week where I solve one answer and punt on another.

TWC Task #1, Happy Women Day

jaredor submission for Task #1

Well, "solve" may be a strong word for what I did with this problem, at least for my programming conscience. The problem statement was simple, but had no requirements for an acceptable solution other than what you could infer from the example solution in the problem statement. However I did give not one, but two solutions, so that's not totally lazy, even if each, on its own, is lazy, right?

--lazy solution

Perl Weekly Challenge 181: Sentence Order and Hot day

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

Spoiler Alert: This weekly challenge deadline is due in a few of days from now (on Sept. 11, 2022 at 23:59). 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: Sentence Order

You are given a paragraph.

Write a script to order each sentence alphanumerically and print the whole paragraph.

Example:

My Favorite Warnings — A Belated Introduction

Look, that's why there's rules, understand? So that you think before you break 'em. — Terry Pratchett, in Thief of Time.

A couple installments into this series of blog posts, I realized an introduction to Perl warnings would be appropriate, with some words on how to turn them off, and why you probably do not want to. Yes, this should have been the first post in the series, but I didn't know it would actually be a series, and, well, maybe better late than never.

The Perl compiler/interpreter can emit warnings when it finds things that may indicate a problem with the code. These are not (yet) enabled by default, but experience has shown that enabling them can highlight conceptual and logic errors.

EV charge calculator from script to Dancer web

Since my last post I wanted to take my EV charge calculator script and convert it into a web form. In this post I breakdown how I migrated the script to a Dancer2 web app.

Just a minor note for those readers who may not be aware, Dancer2 is a "lightweight web-framework for Perl" as described in Dancer2 documentation and can be similar in comparison to Ruby Sinatra and Python Flask.

I started by creating a new project folder with the dancer2 program ( # please note that I am working on a Windows PC and on a linux OS the program would just be named dancer2 )

dancer2.bat -a EVCalc


I then copy over the files inside this directory to my project repository as shown in this commit and moved all the scripts to the bin directory as shown in this commit

I wrote a script to covert the electric rate csv file into a module and added all the calculation code in the main project module. All the html markup is stored in this template file and I sprinkled some CSS which renders a page similar to the screenshot below after submitting some data for calculating the charge of an EV :

calculator_page.png

Thank you for your time, I hope you enjoyed my post.

Railroad diagrams for SQL 2003 and SQL 2016

On github at https://github.com/ronsavage/SQL you will find a repo of SQL stuff created by Jonathan Leffler.

I recently added some files for SQL 2003 and SQL 2016, created by Domingo Alvarez Duarte.

Specifically, look for:
o sql-2003-2.ebnf
o sql-2003-2.ebnf.readme
o sql-2003-2-railroad-diagrams.xhtml
o sql-2016.ebnf
o sql-2016.ebnf.readme
o sql-2016-railroad-diagrams.xhtml

I'd suggest downloading the *.xhtml files and viewing them locally, rather than hammering the on-line convertor mentioned in the readme files, which accepts *.ebnf files and displays these railroad diagrams.

And that begs the question: Is there any Perl code which converts a grammar into a railroad diagram?

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.