Taint in Perl
Last night, I finally nailed it with the help of my best friend. "Taint" can no longer scare me.
Last night, I finally nailed it with the help of my best friend. "Taint" can no longer scare me.
These are some answers to the Week 212 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on April 16, 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.
You are given a word having alphabetic characters only, and a list of positive integers of the same length.
Write a script to print the new word generated after jumping forward each letter in the given word by the integer in the list. The given list would have exactly the number as the total alphabets in the given word.
Example 1
One of the steps of debugging Perl can be to find out what is actually in a string. There are a number of more-or-less informative ways to do this, and I thought I would compare them.
For this I used two short strings. The first was just the concatenation of the characters whose ordinals are 24 through 39; that is, 16 ASCII characters straddling the divide between control characters and printable characters. The second was a small variation on the first, made by removing the last character and appending "\N{U+100}"
(a.k.a. "\N{LATIN CAPITAL A WITH MACRON}"
) to force the string's internal representation to be upgraded.
The results given below include the version of the module used, the actual code snippet that generated the output, the output itself, and any comments I thought relevant. All subroutines used to dump strings are exportable except for those called as methods. The sample code makes fully-qualified calls because of duplication of subroutine names between different modules.
On github, I've released MooseX::Extreme.
It's based on years of experience being the lead designer of the Corinna project and trying to figure out how we can get a version of Moose which is safer and easier to use, including removing a lot of boilerplate. This code:
package My::Class {
use MooseX::Extreme;
... your code here
}
Is sort of the equivalent to:
After a very long time, I found time to blog and here is my journey to deal with memory leak in Perl.
These are some answers to the Week 212 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
Spoiler Alert: This weekly challenge deadline is due in a few days from now (on April 16, 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.
You are given a word having alphabetic characters only, and a list of positive integers of the same length.
Write a script to print the new word generated after jumping forward each letter in the given word by the integer in the list. The given list would have exactly the number as the total alphabets in the given word.
Example 1
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
my $year = ( localtime() )[5] + 1900;
or maybe
my ( undef, undef, undef, undef, undef, $year ) = localtime(); $year += 1900;
Neither is particularly self-documenting, and the latter is much more verbose than we expect of Perl.
Hello everybody,
after a long time of waiting it is finally time - we cordially invite you
to the German Perl/Raku Workshop 2023.
Next year's workshop will take place from Monday 28 February to
Wednesday 1. March in the Saalbau Gallus in Frankfurt am Main.
Reminder: Until April 30th you can get your conference ticket for the low price of $275 per person! Register now!
Don't miss out on booking accommodation at the venue as it is certain to sell out.
Please like the Conference on Facebook and follow it on Twitter
These are some answers to the Week 211 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
You are given a matrix m x n
.
Write a script to find out if the given matrix is Toeplitz Matrix.
A matrix is Toeplitz if every diagonal from top-left to bottom-right has the same elements.
Example 1
Input: @matrix = [ [4, 3, 2, 1],
[5, 4, 3, 2],
[6, 5, 4, 3],
]
Output: true
Example 2
Input: @matrix = [ [1, 2, 3],
[3, 2, 1],
]
Output: false
In which we pine for The Good Place, while visiting The Bad Place.
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
echo source ~/perl5/perlbrew/etc/bash >> ~/.bashrc
or echo source ~/perl5/perlbrew/etc/bash >> ~/.zshrc
depending on your shell.
Once installed, you can see a list of different installable Perl versions by issuing the
perlbrew available
command.
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.
These are some answers to the Week 210 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
You are given a list of integers.
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.
Example 2
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:
my ( $maj, $min, $rel ) = split /[.]/, $version;
my $version_ok = $maj > 3 || (
$maj == 3 && ($min > 6 || (
$min == 6 && $rel >= 8
))
);
Про перл по-русски маловато пишут, вот и будем по возможности наполнять знаниями
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.
These are some answers to the Week 209 of the Perl Weekly Challenge organized by Mohammad S. Anwar.
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.
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.
Example 1:
The open or die
idiom is fairly ubiquitous in Perl. To be useful, the exception should say something about what went wrong: open ... or die "Open error: $!"
, for example.
The $!
built-in variable (a.k.a. $ERRNO
or $OS_ERROR
if use English;
is in effect) gives you access to the C language errno
variable, which through the magic of Perl interpolates an error message appropriate to the error given.
But there are times when some error analysis is in order. Fortunately, $!
is a dualvar
, so if you access it in numeric context rather than string context, you get the actual numeric value of the error code. But for both portability and maintainability you don't want to compare $!
to a numeric literal. Thus, Errno
. For example:
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.
blogs.perl.org is a common blogging platform for the Perl community. Written in Perl with a graphic design donated by Six Apart, Ltd.