
perlancar
- Website: twitter.com/perlancar
- About: #perl #indonesia
Recent Actions
-
Posted Day 24: Games! to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
I'll close this series by mentioning that in A…
-
Posted Day 23: App::chart and Text::chart to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted Day 22: Safer system() alternative (Sys::Run::Safer) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted Day 21: Checking if a string contains shell wildcard (String::Wildcard::Bash) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
A few months ago, during work with shell tab c…
-
Posted Day 20: Creating test databases (Test::WithDB) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Here's one little module that can help you cre…
-
Posted Day 19: Tracing your Perl program's execution (App::plstrace) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted Day 18: Checking unsaved files (File::Unsaved) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
No, I'm not tempted to do a pun, despite the a…
-
Posted Day 17: Checking process existence and listing processes (Proc::Find) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted Day 16: Making tab completion setup seamless for users (App::shcompgen) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
I've created a couple of frameworks that make …
-
Posted Day 15: Words on CPAN (App::wordlist) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Some of you might already know that there are …
-
Posted Day 14: What $! The $? (Proc::ChildError) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Finding out OS error message in Perl is pretty…
-
Posted Day 13: *PAN to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
What is XPAN you say? I wanted to write *P…
-
Posted Day 12: A fatpackable, SSL-aware HTTP::Tiny (but sadly, with a catch) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Okay, this one is a silly proof-of-concept, an…
-
Commented on Day 11: Tab-completion galore (App::{PM,Pl,Prog,Dzil,Git}Utils)
After this article was written, I've also added App::DistUtils. PMUtils recently adds a convenient shortcut that I often use: if you type 'dzp' it will be changed into 'Dist/Zilla/Plugin/'. So will 'pwp' into 'Pod/Weaver/Plugin/' and 'pws' into 'Pod/Weaver/Section/'. I plan...
-
Posted Day 11: Tab-completion galore (App::{PM,Pl,Prog,Dzil,Git}Utils) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Ever since I got interested in doing shell tab…
-
Posted Day 10: Finding module's path and more (Module::Path::More) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted Day 9: Set operations with files (App::setop) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Have you ever encountered one or all of these …
-
Posted Day 8: Stopwatch (App::stopw) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Okay, this post couldn't be simpler. ="…
-
Posted Day 7: Set screensaver timeout from the command-line (App::SetScreensaverTimeout) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Here's the problem statement: For safety/priva…
-
Commented on Day 6: Think globally, act localizably (File::umask, Locale::Tie, Unix::setuid)
Thanks for your input. I'm not sure what you meant by "saved IDs". Come to think of it, Unix::setuid is not necessary at all, because I might as well just localize $, et al directly! The only convenience provided by...
-
Posted Day 6: Think globally, act localizably (File::umask, Locale::Tie, Unix::setuid) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Local variables or dynamic scoping is a very n…
-
Commented on Day 5: Look ma, no 'argument list too long'! (App::rmhere)
perl -e 'chdir "BADnew" or die; opendir D, "."; while ($n = readdir D) { unlink $n }' Yup, I remember that Randal's post. And the above is essentially what the rmhere script does, with some options and progress reporting...
-
Posted Day 5: Look ma, no 'argument list too long'! (App::rmhere) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
If you spend enough time on a Unix/Linux shell…
-
Posted Day 4: Date calculator shell (App::datecalc) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
My habit for the past decade or so, back when …
-
Commented on A small puzzle for you
Don't forget to package the solution to a module, for the rest of us :)...
-
Posted Day 3: Diff-ing your database structure (DBIx::Diff::Struct) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Frankly, I was a bit surprised when searching …
-
Commented on Day 2: When uniq is not unique enough (App::nauniq)
$ perl -ne'$h{$_}++||print' input.txt Yup, that is what nauniq essentially does (plus some options)....
-
Posted Day 2: When uniq is not unique enough (App::nauniq) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
Any Unix user probably knows about the uni…
-
Posted Day 1: Slicing and dicing your JSON (App::jpath) to perlancar
About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.
-
Posted perlancar's 2014 Advent Calendar to perlancar
About the series: Introduction to a selection of 24 modules which I first published in 2014. These exclude modules which I have blogged before.
Table of contents:

Comment Threads
-
Aristotle commented on
A small puzzle for you
my ( $i, %index ) = 0; $index{ $_ } //= $i++ for @a, @b, @c; for ( \( @a, @b, @c ) ) { my @rearranged; @rearranged[ @index{ @$_ } ] = @$_; $#rearranged = keys %index; @$_ = @$rearranged; }
Untested. Downside is the double copy.
-
Aristotle commented on
A small puzzle for you
I believe it takes linear time in the length of the inputs, while they take order (n log n).
That would be nice if this were C, but it’s Perl. So the algorithm may be linear, but due to huge amounts of op dispatch, sub call overhead etc, its implementation in Perl likely has a humongous constant factor, which a big-O analysis hides. In order to actually see it outrun the algorithms that are worse in big-O terms, you’ll probably have to feed it inputs on the order of six digits, maybe even seven or more.
Optimising Perl code usually means finding a…
-
tlrrd commented on
A small puzzle for you
use warnings; use List::MoreUtils qw(uniq); my @in = ( [ 'b', 'c', 'f' ], [ 'a', 'd' ], [ 'c', 'd', 'e' ], ); my $i =0; my %indexes = map {$_ => $i++} sort uniq map @$_, @in; foreach $r (@in) { my @new; @new[$i-1,@indexes{@$r}] = (undef,@$r); $r = \@new } use Data::Dumper; print Dumper \@in;
Not sure if it had to be in place or sorted, but I believe this works.
With apologies to Moritz, whose framework I stole. I would have used Aristotle's uniq replacement, but $work perl is only 5.10.1
-
pru-mike commented on
A small puzzle for you
Yet another solution http://pastebin.com/7HSB8YTW
-
Leon Timmermans commented on
Day 6: Think globally, act localizably (File::umask, Locale::Tie, Unix::setuid)
Thanks for your input. I'm not sure what you meant by "saved IDs".
You may want to read Setuid Demystified first before writing any kind of setuid wrapper.

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.