Thursday, May 06, 2010

Finding all JAVA imports in a Specified Directory (& sub-directories)

Here is a little (Li | U)nix command line script that looks through a given directory and extracts all of the JAVA import statements, sorts them and then prints them to STDOUT.

find ./someJavaDir/ -type f -name '*.java' \
-exec grep '^import .*$' '{}' \; | \
sort | uniq | sort | awk '/import/ {print $2 }'

Basically, replace ./someJAVADir/ with the actual directory that you would like to search for JAVA imports.

Tuesday, April 27, 2010

Getting rid of empty XML elements using XML::Simple

Sometimes it is necessary to remove empty XML elements from XML documents (need a condensed message, etc) and doing so can be a difficult task to achieve! Well, here comes XML::Simple to the rescue...
#!/usr/bin/perl -w
use strict;
use XML::Simple;
use Data::Dumper;
my $xml = <<EOF;
      <RUNDATE>2010-04-23 12:04:41</RUNDATE>
    <service> </service>
           <NTV_DISPLAY_VALUE>Need start date </NTV_DISPLAY_VALUE>
       <service> </service>

# use XML simple to process the XML
my $xs = XML::Simple->new(

      # remove extra whitespace
      NormaliseSpace => 2,
      # keep root element
      KeepRoot       => 1,
      # force elements to arrays
      ForceArray     => 1,
      # ignore empty elements
      SuppressEmpty  => 1
# read in the XML
my $ref = $xs->XMLin($xml);

# print out the data structure
# shows you how to access the data
print Dumper($ref);

# print out the XML minus the empty tags
print $xs->XMLout($ref);
Running this sample code then produces (minus the Data::Dumper text):
    <RUNDATE>2010-04-23 12:04:41</RUNDATE>

Tuesday, February 16, 2010

Firefox (64 bit)

Just a quick note for those of you wanting a 64bit version of Firefox!

You can obtain a 64bit version here! For those of you that are daring, download and install (version is based on a time stamp).

For those wanting something that works, you should download a version after the list of files for (e.g. Firefox 3.6 below).

JAVA is available (and more stable from what I can tell) in 64bit flavors and I would recommend installing a 64bit version after installing a 64 bit version of Firefox
Note that Flash is not available for 64 bit browsers yet (unless you are on linux).

Thursday, January 28, 2010

Posting to Blogger from Perl

Here is a little snippet that allows you to post to your Blogger blog from Perl:

use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
    '',    # dont change
    Hello    => '',         # dont change
    Port     => 587,                      # dont change
    User     => '', # change to your username
    Password => 'password'                # change to your password

# you email address associated with the blog

# the address to send the post to

# blog post body
$mailer->datasend("Subject: Title of my blog post\n\n")
  ;                                       # keep the trailing \n\n!
$mailer->datasend("The text of my post here\n");

# end blog post

Let me know how this works for you!

Thursday, January 14, 2010

Mapping OWL ontologies into PERL

Unlike in JAVA, there doesn't exist a way in PERL to generate modules from Web Ontologies (OWL). Well, not until recently!

As part of a bigger effort, the CPAN module, SADI, contains a script for generating fully functional PERL modules from Web Ontologies. The script is called and is automatically installed along side the SADI module. Under the hood it is using RDF/OWL parsing code from PLUTO (a module built on from a project from IBM).

 I wont go into the details for how to use this module here (there is ample documentation available on CPAN for this module). I would like to point the interested reader to the documentation for generating the Perl modules. Go to and at the very bottom you will see under the "Other Files" header a link called doc/working_with_datatypes.html. That file should get you going.