Perl: remove element from a list/array

You can easily push an element to a list/array, but when it comes to deleting an element, unless you know exactly its index number (which is rarely a case, as far as I’m concerned), things get unreasonably complicated.

I googled around and talked to people on IRC here’s what seems to be the best approaches:

  1. use splice in a loop with a counter
  2. use List::UtilsBy qw ( extract_by );

splice(); proved to be a really hard case. The following code will only remove 1st occurence in an array and ignore the rest, due to the fact that splice causes elements in a list to update their index numbers, so they get essentially offset and the counter is never adjusted for this fact (because I’m too lazy to figure out how). This code will do the job,  if your list contains unique elements  only, though.


use strict;
use warnings;

my @arr = (1, 2, 3, 4, “abc”, “zxy”, “qwerty”, “abcdef”);

my $index = 0;

foreach (@arr) {
if ($_ =~ m/abc.*/i) {
splice (@arr, $index, 1)
} else { $index++ }

If you print @arr to stdout you’ll see that abcdef is still there.

By and large, it’s a bad idea to modify an array in a for loop. If you one of a pretty, intuitive way to write a code that removes elements from an array do let me know, please.

extract_by looks like a real deal, but I abandoned it before I started really using it because I’ve realized that my code didn’t actually need to delete any elements from a list at all lol

Placing Evolution windows to specific viewports with Compiz

Compiz has lots of nifty plug-ins and one of them is called Place. What it does essentially it takes a window and puts it on a specific desktop you tell it to.

The tricky part is to write rules to select windows. Evolution proved to be quite a pain to handle. I usually use 6 virtual desktops, or viewports in Compiz parlance. I have two rows of them, each has 3 virtual desktops. I’m used to having an e-mail client running in viewport 3, row 1 (X3:Y1) web-browser and console in viewport 1 (X1:Y1).

Well, initially my idea was to  grab a Window Title for Evolution’s Compose Message window and have it explicitly excluded in the rules. That kind of approach worked just fine on my office workstation where I use Thunderbird, but with Evolution this sort of rule:

title=Evolution & !title=”Compose Message”

Just didn’t work. What happened was either Compose Message window would be still forcibly placed to viewport 3, or, totally weird, main Evolution window would be transferred to active viewport and Compose Message window would take place of main Evolutoin window defined by Place plugin rules (in my case viewport 3, X3:Y1).

But as I said a little earlier, I keep my Chromium window in viewport 1 and when I click an “e-mail to” link I’d love to see Compose Message window in viewport 1, or in other words I want it to follow the viewport I’m working in. Well, that logic expressed in a rule above proved to be a total failure. I tried literally all the options for matching rules: window class, title, role, etc. — none of them worked. I’ve actually almost given up on this idea to take control of Evolution’s windows and left the rules as they were the last time I messed around with Place settings.

Eventually, what I ended up with, though, and it comes as a surprise to me as well, was a simple:


Which was created sort of accidentally, a leftover of the code from the last time I attempted to figure out the matching rules for Evolution, but it turned out to be exactly what I needed.

So, if you need to forcibly place Evolution on its launch to any viewport, just use this rule to match the Evolution main window. That’s it. Compose Message will follow your viewport.

If you feel a little uncomfortable with Compiz’s matching rules syntax, don’t worry I felt it was a little unusual as well! Here’s a nice post, though, that breaks down the most important aspects of the window matching deal:

yaourt Proxy Settings

In Arch Linux, getting yaourt that is being run as normal user (which is a requirement of the program) to work with proxy was a bit of a challenge.

On my system I have proxy settings setup this way:


export http_proxy;
export ftp_proxy;
export all_proxy;
export https_proxy;
export no_proxy;

When run as normal user yaourt relies on sudo to call pacman to perform package management in the system. The trouble is that when sudo is invoked by yaourt it doesn’t keep your *_proxy variables. The solution is to tell sudo to explicitly keep those variables whenever it’s invoked.

Continue reading