Tag Archives: perl

Removing leading whitespace in file with perl.

Do you ever have code with such poor formatting that you just need to start over? This will let you remove all leading whitespace from every line in the file. I’ve found it handy every now and then. perl -i -pe’s/^\s+//’ file.c

Posted in Programming, Webhosting | Also tagged , | Leave a comment

Resolve IP address from hostname with perl.

Here is a small section of perl code that I stumbled upon that resolves an IP from a supplied hostname. Written by detour@metalshell.com. use Socket; use strict;   sub hostname { my (@bytes, @octets, $packedaddr, $raw_addr, $host_name, $ip); if($_[0] =~ /[a-zA-Z]/g) { $raw_addr = (gethostbyname($_[0]))[4]; @octets = unpack("C4", $raw_addr); $host_name = join(".", @octets); } else [...]

Posted in Programming, Webhosting | Also tagged | Leave a comment