package libyn::LinguaName; use strict; use warnings; use Fcntl ':flock'; BEGIN {   use FindBin;   use vars qw(@gfrequence $gpkgpath);   $gpkgpath = "$FindBin::Bin/"._ _PACKAGE_ _;   $gpkgpath =~ s!::!/!g; } use constant FILE_BOYS   => "$gpkgpath/boys.txt"; use constant FILE_GIRLS   => "$gpkgpath/girls.txt"; use constant FILE_SURNAMES   => "$gpkgpath/surnames.txt"; @gfrequence = (1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3); sub new {   my ($class) = @_;   my $self = {};   bless $self, $class;   $self->{-boys} = _read_file(FILE_BOYS);   $self->{-girls} = _read_file(FILE_GIRLS);   $self->{-surnames} = _read_file(FILE_SURNAMES);   return $self; } sub gen_people {   my ($self, $count) = @_;   my @retval = ();   return () if $count <= 0;   while($count--) { push @retval, $self->gen_person(); }   return @retval; } sub gen_person {   my ($self) = @_;   return $self->gen_name(); } sub gen_name {   my ($self) = @_;   my $count = _get_rand_part(@gfrequence);   my $allnames = [$self->{-boys}, $self->{-girls}];   my $names = _get_rand_part(@{$allnames});   my @name = ();   while($count--) { push @name, _get_rand_part(@{$names}); }   push @name, _get_rand_part(@{$self->{-surnames}});   return join ' ', @name; } sub _get_rand_part {   my (@array) = @_;   return $array[int(rand(scalar(@array)))]; } sub _read_file {   my ($file) = @_;   my $arrayref = [];   if(open(FILE, "< $file"))   {      flock FILE, LOCK_SH;      while(my $entry = )      {         chomp $entry;         push @{$arrayref}, $entry;      }      close(FILE);   }   return $arrayref; } 1;