Brain Goo

Carpe Crap ‘em

Brain Goo header image 4

Entries Tagged as 'Programming'

PERL How To Print A List Without A Loop

February 6th, 2009 · No Comments

PERL has a built-in function called join() that will concatenate a list with a given string. The official perldoc states:
join EXPR,LIST
Joins the separate strings of LIST into a single string with fields separated by the value of EXPR, and returns that new string. Example:
$rec = join(‘:’, $login,$passwd,$uid,$gid,$gcos,$home,$shell);
From the code example, you can make CSV [...]

[Read more →]

Tags: How Tos · Programming · Software · perl

perl howto push a hash onto an array

August 12th, 2008 · 1 Comment

use Data::Dumper;
my @array;
push @array, {‘key1′ => ‘value1′, ‘key2′ => ‘value2′};
push @array, {‘key1′ => ‘value1′, ‘key2′ => ‘value2′};
push @array, {‘key1′ => ‘value1′, ‘key2′ => ‘value2′};
print Dumper(@array);
Will give you:

$VAR1 = {
‘key2′ => ‘value2′,
‘key1′ => ‘value1′
};
$VAR2 = {
‘key2′ => ‘value2′,
‘key1′ => ‘value1′
};
$VAR3 = {
‘key2′ => ‘value2′,
‘key1′ => ‘value1′
};

Snazzy!
Did you find this post useful or have questions or comments?  [...]

[Read more →]

Tags: How Tos · Programming · perl

Quick Character Escaping in PHP

October 10th, 2007 · No Comments

When writing PHP web apps, I tend to run in to a portability issue when dealing with SQL connectivity. Since I can’t count on having the PEAR DB module available, I rolled my own set of functions to interact with a MySQL database.
The problem lies in escaping characters in your SQL queries. Do [...]

[Read more →]

Tags: Programming · SQL · php