December 2014 Archives

Day 24: Games!

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 August I created a few simple text-based games: Games::WordGuess, Games::Hangman, Games::ArrangeNumber. The reason I did this origin…

Day 23: App::chart and Text::chart

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

metacpan.org/pod/Text::Graph">Text::Graph module, which I have also used, but ran into some minor problems and limitations in formatting. Unfortunately there's not much thing to show right now as the only type of chart…

Day 22: Safer system() alternative (Sys::Run::Safer)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

Sys::Run::Safer is an attempt to create a safer API for running programs.

As we might already know, Perl's system() may or may not call a shell depending on a number of things. If we want to avoid a shell, doing system @ary or even system $cmd, @args is not…

Day 21: Checking if a string contains shell wildcard (String::Wildcard::Bash)

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 completion, I wanted a routine to know if a string contains a wildcard. For example, if I have this on the command-line buffer: emacs f*txt and press Tab, shells will usually be helpful and show me the list of filenames matching that wildcard. So I wanted to test whether f*txt contai…

Day 20: Creating test databases (Test::WithDB)

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 create dummy databases during testing: Test::WithDB. It's great together with Test::DatabaseRow (which happened to be featured in this yea…

Day 19: Tracing your Perl program's execution (App::plstrace)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

plstrace is a Perl script which can be used to trace your Perl program's execution. There are other "tracing" modules ="https:…

Day 18: Checking unsaved files (File::Unsaved)

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 aptness of the situation :-)

File::Unsaved is yet another one of my little modules. Its one and only task is to check whether a file is "unsaved", that is, opened in an editor and has unsaved modifications. Currently it has support for sever…

Day 17: Checking process existence and listing processes (Proc::Find)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

Proc::Find is little module that can help you write this shell idiom in Perl and avoid shelling out:

# check a process by name
ps ax | grep -q mplayer
if [[ $? == 0 ]]; then echo "mplayer process exists"; fi
pgrep mplayer
if [[ $? == 0 ]]; then echo "mplayer process exists";…

Day 16: Making tab completion setup seamless for users (App::shcompgen)

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 it easy for Perl developers to add tab completion feature to their scripts (and am planning to write another one). One is Perinci::CmdLine, which I recommend and use a lot more myself but requires you to immerse yourself with the concepts /users/perlancar/2014/12/index.html

Day 15: Words on CPAN (App::wordlist)

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 some wordlists on CPAN, under the Games::Word::Wordlist:: namespace. These lists can be used for, as the package name suggests, word games like Hangman or Word Search or Scrabble, but can also be used for other purposes, among others: cracking/bruteforce dictionary, password generation, feed…

Day 14: What $! The $? (Proc::ChildError)

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 straightforward: just print out the $! variable. Example:

open my $fh, ">", "somefile" or die "Can't open file: $!";

The $! is pretty magical, it can return an integer (errno) or a string.

However, finding out child error message is not equally straig…

Day 13: *PAN

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 *PAN, but since that is not a valid module name (or perhaps it is? maybe there's some word character somewhere in the set which resembles an asterisk/star?) I settled with XPAN. The XPAN::Query explains it and I quote: "XPAN is a term I coined for…

Day 12: A fatpackable, SSL-aware HTTP::Tiny (but sadly, with a catch)

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, and currently incomplete. But nevertheless might fit your need in some situation, like for testing.

It all began a few weeks ago when MELO posted this blog post abou…

Day 11: Tab-completion galore (App::{PM,Pl,Prog,Dzil,Git}Utils)

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 completion with Perl, I've been trying to add tab completion to various programs or, in some cases, (re)creating utilities with tab completion capability. Granted, many of the utilities mentioned here are pretty trivial, but that's okay since tab completion is the main point. Here are some of them:…

Day 10: Finding module's path and more (Module::Path::More)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

NEILB's Module::Path is a handy little module (that comes with a handy little utility mpath to find the filesystem path to a locally installed module. It works by iterating @INC, pretty much like requir…

Day 9: Set operations with files (App::setop)

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 situations?

1) You have two or ten log files, and want to know which IP addresses occur in all of them.

2) You have two SQL dump files, and want to know which tables are in the first but not in the second.

3) You have several files containing a list of usernames to create. You…

Day 8: Stopwatch (App::stopw)

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. stopw (from the App-stopw distribution) is a very simple CLI program. When run, it displays a running stopwatch, upon which you can press Spacebar to let it move down one line (so you can see/note the time you pressed the Space), or Enter to pause/resume, Z to rese…

Day 7: Set screensaver timeout from the command-line (App::SetScreensaverTimeout)

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/privacy reason, I generally want my desktop screensaver to trigger rather quickly (say 3-5 minutes) to minimize prying eyes when I'm away or fall asleep and forget to lock. But when I watch videos, I want to set the timeout to a longer time (say the total duration of the videos plus 1 minute, or (better) …

Day 6: Think globally, act localizably (File::umask, Locale::Tie, Unix::setuid)

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 nifty feature of Perl that nowadays do not exist in a lot of other languages. It allows you to temporarily set the value of a global variable during a block/scope during runtime, effectively localizing global variables. For example, even though some modules provide configuration settings as global var…

Day 5: Look ma, no 'argument list too long'! (App::rmhere)

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, sooner or later you'll be faced with the task of removing files in a directory that contains a lot of those files (in my case, it's usually a Maildir with lots of spam/unread emails). The directory will contain so many files (like 50k or even millions) that doing rm * will fail with…

Day 4: Date calculator shell (App::datecalc)

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 I started learning Ruby, is to use irb (the interactive Ruby shell) as a calculator. I guess one can also use python, but irb was the one that stuck in my muscle memory. perl does have the interactive debugger perl -dee since forever, but by default it does not pri…

Day 3: Diff-ing your database structure (DBIx::Diff::Struct)

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 for an existing CPAN module for this task and found none. There is DBIx::Compare, but it is for database contents and not structure (it can compare two tables' field names though). Hence DBIx::D…

Day 2: When uniq is not unique enough (App::nauniq)

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 uniq command, most often used in combination with sort. For example, to get distinct lines from a file:

% sort somefile.txt | uniq

sort is usually needed because uniq can only skip non-unique adjacent lines. In other words, it does not keep a me…

Day 1: Slicing and dicing your JSON (App::jpath)

About the series: perlancar's 2014 Advent Calendar: Introduction to a selection of 24 modules which I published in 2014. Table of contents.

jpath (from App-jpath distribution) is a simple command-line interface wrapper for JSON::Path written by TOBYINK. With the provided jpath utility you can quickly select and transform some branc…

perlancar's 2014 Advent Calendar

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:

About perlancar

user-pic #perl #indonesia