Tuesday, February 12, 2008

A Perl of Wisdom for Me

Every so often I find a really nice construct I didn't know existed in Perl and I can never remember it. Well I'm going to post them here and see if it kicks my memory into gear.

Copying an array

my $array = [1,2,3]; # From somewhere
my $copy = [@{$array}]; #De-reference array into an anonymous array & assign

Populating a hash from an array via a slice

my %hash;
my @keys = qw/ key key2 key3 /;
@hash{@keys} = (); #Populate hash with keys and no values

#Populate hash with keys from array and values from same position in the assigned list
@hash{@keys} = (1,2,3);

Copying one hash to another

my $input = {key => 1, key2 => 2, key3 => 3};
my %target = (key, 4);
#And now for the copy magic
@target{keys(%{$input})} = values(%{$input}); #1 deref is better than 2 but is ok for tiny calls

Anyway I hope this is of use to someone other than me. If not then it'll be of some use to me.

Tuesday, January 29, 2008

You know when you just think 'Oh FFS'

I've just had one of those moments thanks to an article on Chaotic Java (if you're interested in Java then have a look through the archives as it's all gold). Anyway the article is about Java GC & there was a section about using object reference queues instead of a finalize block (a good idea anyway) and there was a line:

I made NativeImage and Image implement Closeable, a new interface in Java 5 for IO classes that need to be closed.

What?!? There's a ... a ... interface called Closeable. Oh yes there is introduced in Java 1.5 and it's been added to just about every IO class. Wish I had know about that before writing the same try finally block for Readers, Writers, InputStreams & OutputStreams. I know it's a case of 20 lines instead of 3 but it seems annoying. I wonder how many more of these interfaces there are in Java 5 & 6 that could have saved me a few more lines of code. 

Oh well

Monday, January 28, 2008

A less sucky Maven; yes please!

Don Brown has posted an article detailing his grips about Maven2 (for those who do not know Maven is a decent Java build tool but is a bit XML happy). Anyway rather than people like me (who moan but twiddle their thumbs) Don has gone & done something about it.

I can't wait for some of these other fixes coming through especially the one concerning making it easier to write plugins. Do that & I'll be very tempted to write an equivalent to assembly that lets you create deployment tarballs.

Thursday, January 24, 2008

Wow is this my blog?

Has it been that long since I decided to do a blog? Bleedin' heck. What is more worrying is that I've decided that I should start it up again; is it really "starting it up again" if I never really started?

Hopefully it won't be another 2 years until I do my next post (I'm really hoping that it'll only be a few days). Anyway see you all soon whoever you are ... why are you reading this rubbish unless you're a friend and about to take the mick out of me; oh that'll be a nice change

Tuesday, January 10, 2006

Hello Len!

Well it's the normal first post to these things so hell blogspace ... what a crap start hey. Anyway hope that this is going to get better which it won't do and I'll get bored in a bit. If you're wondering who I am well I'm a "Java Programmer " from England (honest guv). I also love beer and chocolate.

Well enough with introductions lets get on with what blogs are meant for; giving the unwashed masses on the internet a voice which we really don't want to hear. Anyway sod it let's go :)

Tapestry 4.0 Release

What a day! Tapestry 4.0 has been released a web framework I have never had anything to do with before but it looks fun; the kind of fun which can also involve rusty pliers :). Anyway found this interesting link to a manual on Tapestry 4.0 & 3.0. Not sure if it's good but what the hell it's free for the first four chapters and that's a lot cheaper than ... well paying for it. Enjoy.