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