Perl...That's Hot!
I would have to say that perl has become my favorite language.
Every programming language has little things about it that make it feel really nice to use, but Perl is overloaded with them. One of my favorite tricks is the map function. The reason I am so fond of it probably stems back to my roots as a young man interested in computer programming. All those weird looking nonsensical codes and symbols were so mysterious. Trying to figure out some ridiculous piece of code is so challenging and fun...
probably why i didn't like taking software development classes in college. Form! classes! who needs them?
Anyway the map function is really simple, but it can make some complicated looking code when things start to get dense. It looks like this
map{"stuff to do with stuff"} @stuff
that might make more sense to me than it makes to you...sorry. let me explain. you give the map function an array, @stuff. for every element in @stuff the function applies the thing in the {} to the element and returns another array. so if you say
The $_ is the variable representing the single stuff element. you get a list like this:
("pie is cool", "steak is cool", "pizza is cool")
this can be particularly helpful if you are writing long database queries. instead of typing the entire thing you can use a map , in combination with a join, and get the whole query in one line.
ex:
who writes a blog about a function...?
Every programming language has little things about it that make it feel really nice to use, but Perl is overloaded with them. One of my favorite tricks is the map function. The reason I am so fond of it probably stems back to my roots as a young man interested in computer programming. All those weird looking nonsensical codes and symbols were so mysterious. Trying to figure out some ridiculous piece of code is so challenging and fun...
probably why i didn't like taking software development classes in college. Form! classes! who needs them?
Anyway the map function is really simple, but it can make some complicated looking code when things start to get dense. It looks like this
map{"stuff to do with stuff"} @stuff
that might make more sense to me than it makes to you...sorry. let me explain. you give the map function an array, @stuff. for every element in @stuff the function applies the thing in the {} to the element and returns another array. so if you say
@stuff = ("pie", "steak', "pizza");
map{"$_ is cool"} @stuff;
The $_ is the variable representing the single stuff element. you get a list like this:
("pie is cool", "steak is cool", "pizza is cool")
this can be particularly helpful if you are writing long database queries. instead of typing the entire thing you can use a map , in combination with a join, and get the whole query in one line.
ex:
$query = join(',' , (map{$dbvals{$_}} @dbcolumns));
who writes a blog about a function...?




1 Comments:
But what about php!? I love it when you have to interact with a database.. it's easier it seems.. at least at first. I haven't used it all that much.
Post a Comment
Links to this post:
Create a Link
<< Home