Created
July 17, 2014 09:49
-
-
Save mattfoster/4ad5b72cf13697b9bd06 to your computer and use it in GitHub Desktop.
A quick script to generate random client names
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env perl | |
# Generate random client names | |
use warnings; | |
use strict; | |
use Carp qw( croak ); | |
use Readonly; | |
Readonly my @COMPANY_TYPES => qw( Ltd PLC B.V. S.p.a. LLC LLP Incorporated ); | |
sub random_dictionary_word { | |
my $dict = shift || '/usr/share/dict/words'; | |
srand; | |
my $line; | |
open(my $dict_handle, '<', $dict) or croak "Could not open dictionary $!\n"; | |
rand($.)<1 and ($line=$_) while <$dict_handle>; | |
close $dict_handle; | |
chomp $line; | |
return $line; | |
} | |
sub random_company_suffix { | |
return $COMPANY_TYPES[rand @COMPANY_TYPES]; | |
} | |
sub random_client_name { | |
my $words = shift || 2; | |
my $suffix = shift || 1; | |
my @name; | |
while ($words) { | |
push @name, ucfirst(random_dictionary_word); | |
$words--; | |
} | |
if ($suffix) { | |
push @name, ucfirst(random_company_suffix) | |
} | |
return join(' ', @name); | |
} | |
warn random_client_name, "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some examples of output: