Perl Notes

This didn’t go very far because what was going to get done in Perl was not to be ultimately.

Welcome to Perl...

Handy subroutine for Perl (at the point where I am now anyway):

	sub println
	   my( @args ) = @_;           # pick up subroutine arguments
	   my  $arg;

	   foreach my $arg in (@args)  # arguments treated as a list/array
	   {                           # hmmm... braces required anyway!?
	      print "$arg";            # double quotes ensure "interpolation"

	   print "\n";                 # this is the "ln" part of println

Here’s another one:

	sub askyesno
	   my( $prompt ) = @_;
	   my  $output = undef;       # hey, it’s interpretive, so who cares?

	   print "$prompt";

	      print "(yes/no) ";      # (insist: but we’ll also tolerate y/n)
	      $output = <STDIN>;
	      chomp $output;          # stdin also leaves the \n on $output
	   until ($output eq "yes" || $output eq "n" || $output eq "no" || $output eq "n");

	   return ($output eq "y") ? "yes" : ($output eq "n") ? "no" : $output;

	my $output = askyesno("Are you having fun yet? ");

	print "$output\n";

More handy stuff...

Sample response is given here...

	$ perl -e '$! = 16;print "$!\n"'
	> Device or resource busy

	$ perl -mErrno -e '$!=16; print grep($!{$_}, keys(%!)), ": $!\n";'
	> EBUSY: Device or resource busy

	# search and replace across a bunch of files...
	$ perl -pi -e 's,pattern,replacement,' *

	--------------------- -----------------------------------------
	#!/bin/env perl

	use Errno;

	die("Usage: errno \n") unless @ARGV == 1; $!=$ARGV[0]; print grep($!{$_}, keys(%!)), ": $!\n";


It's a whole world of Perl out there. There's something called CPAN which is a sort of "underneath the belly" thing for maintaining Perl modules. (Bugzilla is based partly on Perl and such modules.) Installing Bugzilla, I had borked the (required) installation/configuration of CPAN, I knew it, but I couldn't figure out how to unbork it. I just did (mostly).

A big problem is that Perl/CPAN is (are) still stuck in the world of ftp. I don't know anyone who uses ftp any more on Linux. We just no longer really do that. I'm not yet certain fixing what I fixed here solves that, but I was able to do some CPAN installs cleanly. This is a good link:

Things to know:

  1. Do not run Perl and CPAN as root--ever. There is great risk (from what I've read) of wiping your hard drive.
  2. To run a CPAN shell, the source of all Perl module happenings, do
    	$ perl -MCPAN -e shell
  3. If you've borked your CPAN stuff by choosing unwisely, zero it out by launching (#2 above), then issing the shell command
    	cpan[1]> clean

    Then, start over and take the defaults including the big one in letting the thing make all the set up on its own. You will have to help it decide on a list of mirrors at one point. Don't forget to commit changes:

    	cpan[2] o conf commit

    After cleaning up and starting over, I was able to install YAML, the failure of which prompted me to dig into this in the first place.

    	cpan[3]> install YAML

For one thing, as I was on Ubuntu server and hadn't installed them, I had to get all the build tools (make et al.) since these are used by...

	$ /usr/bin/perl --all work the installation. Set this up using:

	$ apt-get install build-essential

I still had some nasty things going on due probably to having tried to do this stuff from root. I'll update this as soon as any make real problems that I have to resolve.

Other, relevant links