Thursday, September 25, 2008

Perl constants with inheritence

package Base;

use strict;

use constant MY_CONST => 'Base Constant';

1;

package Child;

use base qw( Base );

sub printMyConst
{
my $self = shift;
print $self->MY_CONST;
}

1;

Child->printMyConst();

Wednesday, August 13, 2008

Vim Settings

In Vim, type

:set<enter>

to view all your current settings.

Sunday, May 4, 2008

Spaces in file names, oh no!

It is not a normal thing to have spaces in file names of directory names when you are in Linux. That does not mean you can't, but it can cause pain and suffering when trying to use common command line tools.

Example: I just copied all my music over from my Windows partition. Unfortunately, I use to buy music off of Itunes. This left me with part of my music collection unusable. Well, I am not going to spend the time figuring out how to unsuck my songs, so I want just want to remove them all.

So, I start off looking at the file names and notice that the protected ones are of type m4p. Perfect. I can just look for those and delete them.

First, let me find all the protected songs.

$ find . -type f | grep '.m4p'

Awesome, I now know where all the files I want to delete.

In case I need to remember that I actually used borrow a song from Apple, I am going to save a list of songs that I am going to delete.

$ find . -type f | grep '.m4p' > ~/the_itunes_bonage.out

Now for the big show, "DELTEETED!!!!!" (sorry, strongbad reference).

$ find . -type f | grep '.m4p' | xargs rm

Wait, crap. That didn't work. Apparently, xargs treats anything separated by whitespace as an individual file.

Searching the interweb tells me to use --print0 on find and -0 on xargs. This uses null delimination instead of new lines. Well, that is great, but I really need to filter out all the songs that I want to keep.

You can ask grep to also treat null as the delimiter by adding the --null option. This didn't work for me. I didn't spend any extra time figuring out why not either.

Looks like I need to quote the damn things myself.

$ find . -type f | grep '.m4p' | awk '{print "\""$0"\""}' | xargs rm

There we go.

Moral of the story:
  • Don't use spaces in filenames
  • By music from Amazon MP3, it is DRM free!!
-- Matt

About Me

Seattle, Washington, United States