Brain Goo

Carpe Crap ‘em

Brain Goo header image 4

Entries Tagged as 'perl'

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 [...]

[Read more →]

Tags: How Tos · perl · Programming · Software

perl howto push a hash onto an array

August 12th, 2008 · 2 Comments

This could also be called how to make an arrays of hashes. The basic idea is to create a list of items that when iterated, returns individual hashes. use Data::Dumper; my @array; push @array, {‘key1′ => ‘value1′, ‘key2′ => ‘value2′}; push @array, {‘key1′ => ‘value1′, ‘key2′ => ‘value2′}; push @array, {‘key1′ => ‘value1′, ‘key2′ => [...]

[Read more →]

Tags: How Tos · perl · Programming

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); $ip1 = $ip1[0] * 2**24 + $ip1[1] * 2**16 + $ip1[2] * [...]

[Read more →]

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