• Get the Flash Player to see the slideshow.
  • Categories

  • Authors

  • Great Quotes

    Ruby inherited the Perl philosophy of having more than one way to do the same thing. I inherited that philosophy from Larry Wall, who is my hero actually. I want to make Ruby users free. I want to give them the freedom to choose. — Yukihiro Matsumoto - inventor of Ruby

Get in touch...

To have a chat about
your CMS needs...

Call us 0207 193 2014
or
Email us on

Archive for the ‘Perl’ Category

Print Time – Perl

Thursday, November 27th, 2008

A key requirement for any log is to log the time and date of any action taking place in a script.  The command below will print the time to your log in a readable format

print LOG scalar localtime;

The output of this in a log will be as follows;

Thu Nov 27 14:48:48 2008

Note: (LOG) is the log file you adding or appending to

Change a word in many files

Saturday, September 27th, 2008

The below one liner will open all files in its path and change the word ‘MOO’ in any of the files to the word ‘BOO’.

find . -type f | xargs /usr/iw-home/iw-perl/bin/iwperl -i -p -e 's/MOO/BOO/g;'

This script has only been lightly tested so please make a backup of your files before running this!

Find all Branches in TeamSite

Thursday, September 25th, 2008

The below script will look through all the branches in a TeamSite file system and simply list only the branches, not workareas or files and so on.

This script is by no means optimised and could run alot faster by doing checks in the “wanted” sub routine, but it does the job :)

This is useful when running ‘iwmigrate’ and other such tools recursively.

From the command line run the script passing the parameter of the top level branch to search from

Example Usage:

c:\temp\find_all_branches.ipl y:\default\main

#!C:\Perl\bin\perl.exe -w
 
use strict;
use File::Find;
 
my ($area) = @ARGV;
my(@branches, $branch, $directory, @allDirectories);
 
find(\&wanted, $area);
		foreach $directory(@allDirectories){
			if (-d $directory){
				next if ($directory =~ "WORKAREA" || $directory =~ "STAGING" || $directory =~ "EDITION");
					push @branches, $directory;
				}
			}
 
foreach $branch(@branches){
					print "Branch: $branch\n";
				}
 
sub wanted {
	push @allDirectories, $File::Find::name;
	return @allDirectories;
}

The output the script produces is a list of every branch it finds, such as:

Branch: c:\TEMP\branches
Branch: c:\TEMP\branches/default
Branch: c:\TEMP\branches/default/main
Branch: c:\TEMP\branches/default/main/test
Branch: c:\TEMP\branches/default/main/test/sub-branch

A simple log in Perl

Tuesday, September 23rd, 2008

I know this is really easy but I get asked it so often, I thought I would note it down.

The best way to create a log file from Perl is to use log4perl, but it has a bit of a learning curve so try the simple approach for now which is as follows:

open (LOG, ">C:\\Interwoven\\Teamsite\\local\\logs\\mystuff\\debug.log");
 
     print LOG "Starting Program...\n";
 
close LOG;

Anything you wish to write to the log, simply use the ‘print’ statement and you are away :)

Perl Simple File Find

Wednesday, August 27th, 2008

The below example runs and simply prints the file names of files inside the c:\temp folder, you will need to add the behaviour you require on the “print” line:

Command line call:

perl.exe c:\find.pl c:\temp

Script

use strict;
use File::Find;
 
my ($area) = @ARGV;
my(@files, $file);
 
find(\&wanted, $area);
		foreach $file(@files){
			if (-f $file){
				print "File: $file\n";
			}
		}
sub wanted {
	push @files, $File::Find::name;
	return @files;	
}

Result

File: c:\temp/find.txt
File: c:\temp/find2.txt
File: c:\temp/find3.txt
File: c:\temp/find4.txt
File: c:\temp/regfind.exe

Perl Magic One Liners

Wednesday, July 2nd, 2008

This page is dedicated to all the quick one line utilities that are useful when managing an
Interwoven system or any other system that uses many files.

Find all files without metadata of content_type:

find . -name '*.xml' -exec /iw-home/iw-perl/bin/iwperl -e
'$file=shift;system("/iw-home/bin/iwextattr", -g=>
"TeamSite/Metadata/content_type", $file);warn "$file\n"
if $?' {} ';' >/dev/null

Regenerate Recursively

find . -name \*.xml -exec iwregen {} ';'

Check Socket Connection

This is useful to see if firewall is open when debugging OpenDeploy
(Thanks to Steve Martina for this one back in 2001):

/iw-home/iw-perl/bin/iwperl -MIO::Socket -e "$s=new IO::Socket::INET
(PeerAddr=>'localhost',PeerPort=>80,Proto=>'tcp'); print $s?'OK':'fail'"

List the deleted but unsubmitted files in an area (. current dir)

/iw-home/bin/iwlistmod . | grep x+