Use File::Basename to separate a filename from its directory

Question: Using Perl, if I have a string that includes the full path to a file (i.e., it includes both the full path of the directory and the filename), how do I split the string into its directory and filename components?

Answer: Use the basename and dirname methods of the Perl File::Basename module.

The following example shows how to break this string '/Users/al/work/file1.pdf' into its directory and filename components:

A Perl module template (template code for a Perl module)

If you've ever needed some template/boilerplate code for creating your own Perl module, here's some sample code intended to give you just what you wanted. Feel free to copy and paste the Perl code shown below and use it as a template for creating your own modules.

How to use this sample Perl module

If you've never created your own Perl module I recommend first seeing how this sample code works. Here's all you have to do to get it running:

A MySQL database table index example

MySQL FAQ: How do I create a MySQL database table index?

Here's an example of how to create an index on a MySQL database table. In this particular example my table uses the MySQL InnoDB database engine, but that doesn't matter too much -- it just happens to be a MySQL database engine that supports foreign key relationships.

To get started, here's the SQL definition of a MySQL table I've named ftp_files:

How to get SOAP::Lite working with the Apache CXF web service

I'm not going to spend too much time showing this Perl SOAP client solution, but if you're having problems using the Perl SOAP::Lite module as a client running against a modern web service, this sample Perl code may help solve the problem.

First, I'd like to show what my original Perl SOAP client code looked like when I was using it as a SOAP client running against several Axis and XFire web services:

Debug Ant build problems with echo statements

Ant FAQ: How to use echo commands to debug Ant build scripts.

I've been moving back and forth between a ton of different computers lately -- Mac, Linux, and Windows computers -- and I had some problems with an Ant build script. This particular Ant script is complex, and I kept making mistakes, and needed a good way to debug the build process as I set up my application on these different systems.

Syndicate content