Brain Goo

Carpe Crap ‘em

Brain Goo header image 4

Entries Tagged as 'Programming'

perl howto push a hash onto an array

August 12th, 2008 · No Comments

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

Perl code to find an IP A in subnet B/C

June 5th, 2007 · No Comments

my $ip = ‘1.2.3.4′;
my $block1 = ‘1.2.3.0/27′;

if(checkip($ip, $block1)) {
print STDOUT “$ip is in $block1\n”;
}
else {
print STDOUT “$ip is not in $block1\n”;
}

sub checkip() {
my $ip = shift;
my $block = shift;

@ip1 = split(/\./, $ip);
[...]

[Read more →]

Tags: How Tos · Programming · ip addressing · ipv4 · networking · perl