#!/usr/bin/perl # commonStart # This script determines the string that is the common start of the # strings passed as command-line arguments # Cameron Hayne (macdev@hayne.net) January 2005 use warnings; use strict; my @strings = @ARGV; my $numStrings = scalar(@ARGV); if ($numStrings < 2) { print "Must supply at least 2 strings as command-line arguents\n"; exit; } my $sep = chr(0); # null character - presumed not to occur in strings my $common = $strings[0]; for (my $i = 1; $i < $numStrings; $i++) { if ("$common$sep$strings[$i]" =~ /^(.*).*$sep\1.*$/) { $common = $1; } } print "$common\n";