Saturday, February 6, 2010

Late Night Find: BookBook

BookBook

This is a case for the 13" MacBook and MacBook Pros. I want one so badly and literally almost bought it on impulse. $80 is a little steep for me for an impulse buy, so I'll just ogle it and restrain myself.

Thursday, February 4, 2010

Life of a Vendor

Props go out to WoW Moviewatch for making me aware of it, but more specifically to Galenmereth for making a simple yet thought provoking look at the World of Warcraft, Life of a Vendor. This video excellently features the song "I don't know" by Lisa Hannigan which I absolutely love.

The youtube video captions read:
This is a video dedicated to all the vendors who usually only get our coin and not our love. We all love you, even if you are just ones and 0´s!

I enjoyed this and wanted to share.


Hashes are fun

Another day gone and another fun day of Mason and Perl learning.

I should preface this by saying as I am still learning there most likely WILL be errors. Please comment and correct me. I'll gladly edit the post to correct. I am still learning here. :)

#1 Gripe, dealing with Hashes.

Don't get me wrong, I love 'em, and they are incredibly handy, but I spent a good part of the day figuring out multi-dimensional hashes, declaring them and using them. When all is said and done I forgot about how hashes are stored how Perl wants to store them, for better efficiency. Whenever you alter it, it could be in a different order. Oh well. Multi-dimensional arrays that emulate hashes, GO!

Hashes and arrays, as compared to PHP

PHP:

$var = array();
//Empty Array

$var = array(12,23,2);
// Normal Array, each item in their ordered position
// $var[0] == 12, $var[1] == 23, $var[2] == 2

$var = array('coke' => 'soda' , 'paper' => 'wood');
// Associative Array (this is like a hash in perl)

$var = array(
'Dinner' => array(
'steak' ,
'veggies',
'wine'
)
);
//This is a multi-dimensional array and can be used simply by calling the values
//$var['Dinner'][0] == 'steak';

END PHP

<%perl>

# Some background about variables in Perl
# $var - scalar (single variable)
# @var - list (an array)
# %var - hash (an associative array)

$variable = 'ice cream';
@variable = ('breakfast','lunch','dinner');
%variable = { 'breakfast' => 'cereal', 'dinner' => 'Cheese Steak' };

Correction (ty cole)
The '%' sigil represents a symbol that *is* a hash. When you create a hash using curly braces, you're returning a reference *to* a hash. So if you do the assignment you talked here, it doesn't work the way you want.

#So in other words, my free use of { } was wrong. Here is the proper definition of that datatype that actually will return the hash and not the reference to the has.

%variable = ( 'breakfast' => 'cereal', 'dinner' => 'Cheese Steak' );

<%/perl>

You will notice the difference in ( vs. { when you're using an array vs. a hash. For added fun, if you want to reference anything you want to treat it like a scalar. It assumes you want to return a scalar when you reference a hash.

In this case: %variable = { 'breakfast' => 'cereal', 'dinner' => 'Cheese Steak' };

print $variable{'dinner'} will return the scalar 'Cheese Steak' so perl has done right. (note the { brackets again)

Dereferencing
When you read from a hash remember, Perl assumes it's a scaler, to tell it to be something else you need to apply the appropriate prefix.

If %variable had been
%variable = {
'dinner' => {
'Cheese Steak',
'Chips',
'Soda'
}
}

$variable{'dinner'} will still return a scalar but now it'll be the pointer to the sub-hash.

To get to the hash I need to tell perl that what it is returning needs to be another hash which means wrapping it in the hash indicator %{}.

%new_hash = %{$variable{'dinner'}}; #congrats, we now have our sub-hash to read.

Fun stuff. I love that I'm learning!

Wednesday, February 3, 2010

Mason and Me

I've spent the better part of the last couple weeks neck deep in Perl and Mason and really trying to understand the workings of the languages.

Perl:
I think I was spoiled by PHP somewhat. It's a web language, it's made by people who want to do web things so there are functions throughout the language that do the most common things. Perl has libraries, a lot of them, and I'm sure they do everything that PHP could only dream to do, but right now I'm spending most of my time looking for how to do some things that is a simple function call in PHP. I'm sure once I know the tricks/shortcuts/secret handshakes I'll be singing Perl's praises. Regex is nice though.

Mason:
It's very interesting. As a template system it's very convenient. Oh, I just put all my design stuff in the root folder and then every subsequent sub folder will just use the content in the last folder? Swell. It's a lot to think about. I'm making a relatively small section of a site right now in Mason and I can see how it could bloat up very very quickly. My immediate goal for this site (not just the piece I'm working on) is to get a real grasp of how it's laid out and what is really important in the system.