Tuesday, May 26, 2009

perl vs xml vs excel

use Spreadsheet::ParseExcel;
use XML::DOM;
my $doc = XML::DOM::Document->new;

my $xml_pi = $doc->createXMLDecl ('1.0',"UTF-8","yes");
$doc->setXMLDecl($xml_pi);

my $root = $doc->createElement('tests');
$root->setAttribute('xmlns:xsi', "http://www.w3.org/2001/XMLSchema-instance");

my $parser = Spreadsheet::ParseExcel->new(
  CellHandler => \&cell_handler,
  NotSetCell => 1
);

my $workbook = $parser->Parse($filename);
$root->printToFile ($outFile);

exit(0);

  sub cell_handler {

  my $workbook = $_[0];
  my $sheet_index = $_[1];
  my $row = $_[2];
  my $col = $_[3];
  my $cell = $_[4];
 my $myTag;
 my $myText;

  $testName=$cell->value();
  if ($testName !~ m{\w+\.sv}) {$testName = ""; $lastCol = -1; return;}
  $test = $doc->createElement('Test');
  $myTag = $doc->createElement('Name');
  $myText = $doc->createTextNode($cell->value());
  $myTag->appendChild($myText);    #set text content for this tag
  $test->appendChild($myTag);

  if ($implemented == 1) { $root->appendChild($test); } # add new entry only if it's new line

}

Monday, May 25, 2009

install perl module as non-root

perl Makefile.PL, make, make test, make install

The standard way to install a Perl module on Unix is to change into the directory that was created when you unpacked the .tar.gz file, and then type the following sequence of commands:

  perl Makefile.PL
  make
  make test
  make install


This will create a makefile for you, then compile the module, test it, and put it in the correct location for you. This requires that you are logged in as root, so that you can copy files to the Perl library directory, and various other places on your system where the installation will put files.

If you do not have root permissions on the machine where you want to install the module, such as if you wish to install a module in your home directory, just change one of those commands. Instead of

  perl Makefile.PL

type

  #perl Makefile.PL PREFIX=/path/to/where/you/want/it
  perl Makefile.PL INSTALL_BASE=/path/to/where/you/want/it

 make install

That will put all the files in that directory. In order to use modules that are stored in that location, you will need to add the following like to your Perl programs:

  use lib "/path/to/where/you/want/it/perl5"
and, yes, thanks for the comment, local::lib might be easier to install a new module.
  use local::lib "/path/to/where/you/want/it/perl5"