The filetest pragma modifies the behavior of the file test operators (a.k.a. the -X operators.) It has been in core since Perl 5.6.0.
As of Perl 5.36.0 it still has only one sub-pragma, 'access', which applies to the -r, -w, -x, -R, -W, and -X tests. Normally, these tests only consider the mode bits returned by stat(), as discussed in my previous blog post, The File Access Operators: To Use, or Not to Use. But within the scope of use filetest 'access';, these tests consider not only the mode bits, but any ACLs (Access Control Lists) that may be applied to the file -- at least, under POSIX systems. Under systems that do not implement access(), this sub-pragma does nothing.
Taking ACLs into account sounds like a Good Thing, but it comes at a price. Within the scope of the 'access' sub-pragma:
Write a script to get the maximum points. You are allowed to take out (kill) any integer and remove from the list. However if you do that then all integers exactly one-less or one-more would also be removed. Find out the total of integers removed.
Example 1
Input: @int = (2, 3, 1)
Output: 6
First we delete 2 and that would also delete 1 and 3. So the maximum points we get is 6.
I'm going to start this blog by writing a very simple guide on installing Perl using perlbrew.
To install Perl using perlbrew, first visit the website and grab its
curl -L https://install.perlbrew.pl | bash
and paste it in your terminal, and wait for it to do its job.
Now you will have to run
perlbrew init
to initialize perlbrew.
After that you will probably have to add it to your $PATH environment variable as the installation says after it is done downloading. This can be done with a command like
At $work, one of my colleagues who is not in a developer role has started to get into writing code more and more, and I am mentoring him. He's about to work on a productive ticket with Moose for the first time, so I gave him a little reading list, mostly involving selected parts of the documentation as well as Ricardo Signes' excellent talk Moose is Perl.
But then I thought I must have read lots of great blog posts about Moose on the Perl Advent Calendar over the years. I tried to find a few, but had some trouble identifying them easily. So I wrote a quick scraper. Here are all articles that mention Moose since 2010 (where the format of the website changed). Most of them are about Moose or one of the numerous MooseX modules.
Perl has two operators, cmp and <=>, which are basically never seen outside of sort blocks.
That doesn’t mean you can’t use them elsewhere, though. Certainly sort and these operators were designed to work seamlessly together but there isn’t anything sort-specific about the operators per se, and in some contexts they can be the most appropriate solution.
An example would be some code that used to go (almost exactly) like this:
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 26, 2023 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: Special Bit Characters
You are given an array of binary bits that ends with 0.
Valid sequences in the bit string are:
[0] -decodes-to-> "a"
[1, 0] -> "b"
[1, 1] -> "c"
Write a script to print 1 if the last character is an “a” otherwise print 0.
Just in case the problem passed you by, Rene "cavac" Schickbauer has a post discussing a Zlib CVE, and the implications for cpan modules:
I have done a casual grep through my local CPAN mirror (yay for local mirrors!), which has given me a list of potentially vulnerable modules. There are over 90 of them. Yes, there are probably a few false negatives and a few false positive, as i didn't have time to go over each distribution in detail.
Please check your CPAN distributions for any use of zlib.c, libz.c, deflate.c, compress.c and similar variants and update as necessary. If at all possible, i would also recommend to switch to either the zlib provided by the operating system or at least coordinate with other CPAN authors to reduce the number of static copies of the zlib libraries spread all over CPAN modules.
I've been using perlimports a lot at $work. I'm generally quite happy with perlimports, but it can get confused by modules which are being dynamically used. Fortunately, there's one little trick that can help in this scenario.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 19, 2023 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: Minimum Index Sum
You are given two arrays of strings.
Write a script to find out all common strings in the given two arrays with minimum index sum. If no common strings found returns an empty list.
A couple days ago the SD card on a Raspberry Pi lost its beady little mind, and I ended up rebuilding the system from scratch. I generally build my own Perl (also from scratch) and then install the modules I need. So that I can have a log file to rummage through in the event of a problem, I start by configuring the CPAN client interactively, and then doing
$ cpan YAML 2>&1 | tee YAML.log
$ cpan Bundle::CPAN 2>&1 | tee YAML.log
Normally I would now install the modules specific to my use. But when I tried this time I got
HTTP::Tiny failed with an internal error: IO::Socket::SSL 1.42 must be installed for https support
Net::SSLeay 1.49 must be installed for https support
For several years, I spent much time writing code for the Raspberry Pi, including hardware level register C code so that we can use various Integrated Circuit chips and sensors with Perl.
A couple of years ago, I acquired much larger and much more expensive toy, an all-wheel drive, full auto-pilot Tesla Model-X SUV, so of course, I want to write Perl code to access and manipulate it.
In the ensuing two years, I developed several microcontroller-based devices for the car, including one that knows where the car is, and its battery charge and state, and dispslays this information via an LED light strip and an OLED screen inside of my garage, along with an audible alarm that sounds for 1/8th of a second every three seconds if the battery is below a certain threshold so I don't forget to plug the charger in.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on March 12, 2023 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: Keyboard Word
You are given an array of words.
Write a script to print all the words in the given array that can be types using alphabet on only one row of the keyboard.
Time::Piece is a date/time module that replaces the built-in functions gmtime() and localtime(). The replaced functions return a Time::Piece object, with accessors for the compontents of the time. Time::Piece also provides formatting, parsing, and arithmetic.
This module has been in core since Perl 5.9.5. I was able to get it to pass
tests as far back as 5.8.1, though not 5.8.0 or 5.6.2.
Without this module, you would obtain the current Gregorian year in your local zone like this