Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling


by Skeeve (Parson)
on Apr 29, 2003 at 07:28 UTC ( [id://253915]=user: print w/replies, xml ) Need Help??

The image was created using South Park Studio and Gimp.

I was introduced to the monastry by physi. He was my boss in a project.

I picked my name from Robert Asprin's books about M.Y.T.H. Inc. which I really love.

Useful Character Set information: []

perlmonk nodes I often use:

My perl skeleton

#!/usr/bin/perl use strict; use warnings; use Getopt::Long qw(:config no_ignore_case); use Pod::Usage; my ( # options $verbose, $debug, $file, @columns, ); $file= 'default.txt'; help() unless GetOptions( 'v' => \$verbose, 'verbose!' => \$verbose, 'debug+' => \$debug, 'file=s' => \$file, 'c|column=i' => \@columns, 'h|help' => \&help, 'm|man' => \&man, ); sub help { pod2usage(-verbose=>1); } sub man { pod2usage(-verbose=>2); } print "OKAY\n"; # Program goes here... =head1 NAME Getopt::Long / Pod::Usage skeleton =head1 SYNOPSIS [options] =head1 DES‎CRIP‎TION This is a skeleton I use when creating a new perl s‎crip‎t =head1 OPTIONS =over 4 =item B<-v> verbose outoput =item B<-d> =item B<-debug> debug mode =item B<-file> F<filename> specify the file to work with =back =head1 BUGS none yet =head1 TODO much =cut

Things I might need (again) in the future:
  • mkdir -p
    use File::Basename; mkdir_p("some/long/path"); sub mkdir_p { return ((-d $_[0]) or (mkdir_p(dirname $_[0]) and mkdir $_[0], 075 +5)); }
  • IP v4 address manipulations
    #!/usr/bin/perl use strict; use warnings; use Socket; my $ifconfig='/usr/sbin/ifconfig'; # run ifconfig -a open my $if, '-|', "$ifconfig -a" or die "Couldn't run $ifconfig: $!\n +"; while (<$if>) { # find a line with "broadcast" in it # on Solaris this contains all the information I need next unless /inet\s+(.*?)\s+netmask\s+(.*?)\s+broadcast\s+(.*? +)\s*$/; # keep ip address as it is (a dotted string) my $iaddr= $1; # convert the netmask to a "long" my $netmsk= hex "0x$2"; # dito for the broadcast my $brdcst= unpack 'N', inet_aton $3; # How many bits does the netmask have? my $bits= 31-int(log(0xffffffff ^ $netmsk)/log(2)); # Convert the netmask to a "slashed" IP my $network= inet_ntoa(pack "N", ($brdcst & $netmsk)) . "/" . +$bits; # show all info found print "$iaddr\t$network\n"; } close $if;
  • Reverse DNS Lookup
    use Socket; my ($name,$aliases,$addrtype,$length,@addrs) = gethostbyaddr(inet_aton +("")); print $name,$/;
  • Building perl on Solaris with gcc
    • make sure /usr/ccs/bin is not in the path
    • make sure make is in the path for "make test" e.g. by
      ln -s /usr/ccs/bin/make /usr/local/bin
  • Building perl DBI (on Solaris) with gcc
    perl Makefile.PL CC=gcc LD=gcc CCCDLFLAGS=-fPIC OPTIMIZE=-O3
    This is not necessary if you build your own perl as above in which case the normal process will work.
  • Building DBD::mySQL ...
    make sure .../mysql/bin is in your path
  • CSV splitting without modules
    sub csvsplit { my (@result); for ($_[0]) { s/[\015\012]+$//; while (s/^"((?:[^"\\]|\\.)*)"// || s/^'((?:[^'\\]|\\.)*)'// || + s/^([^,]*)//) { push(@result, $1); last unless s/^,//; } } return @result; }

bit-vec for more than 31 bits.

my $vec = []; sub setBit { my($vec, $offset, $val)= @_; my $index= $offset >> 31; my $subset= $offset & 0x7fffffff; $vec->[$index]||=''; vec($vec->[$index], $subset, 1)= ($val & 1); } sub getBit { my($vec, $offset)= @_; my $index= $offset >> 31; my $subset= $offset & 0x7fffffff; $vec->[$index]||=''; return vec($vec->[$index], $subset, 1); }
my old signatures
  • $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
  • s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2024-07-16 02:28 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.